Dear Team,
I have a project on .NET Core MVC Web API with EntityFramewok and MySQL as back-end.

{
public readonly ConfigServerData configServer;
public readonly string EmpCode;
public readonly string DomainID;
public readonly HttpRequest httpRequest;
public CPQuestionMaster(ConfigServerData _config, HttpRequest _httpRequest)
{
configServer = _config;
httpRequest = _httpRequest;
this.EmpCode = Convert.ToString(httpRequest.HttpContext.Items["EmpCode"]);
this.DomainID = Convert.ToString(httpRequest.HttpContext.Items["DomainID"]);
}
public String AddMainQuestion(AddCPQuestionMasterModel addQuestionMasterModel)
{
string responseAddQuestion = string.Empty;
Int32 totalquestions = 0;
CPQuestionMasterModel _resReponseQuestionMasterModel = new CPQuestionMasterModel();
CPQuestionMasterContext DBQuestionMasterContext = new CPQuestionMasterContext();
try
{
if (addQuestionMasterModel.Question_Add_list != null)
{
totalquestions = addQuestionMasterModel.Question_Add_list.Count();
if (totalquestions > 0)
{
foreach (var question in addQuestionMasterModel.Question_Add_list)
{
Int32 QuestionMaster_Count = DBQuestionMasterContext.CP_Question_Master.Count();
Int32 ncount = QuestionMaster_Count + 1;
_resReponseQuestionMasterModel.QID = ncount;
_resReponseQuestionMasterModel.Service = addQuestionMasterModel.Service_Add;
_resReponseQuestionMasterModel.Question = question.ToString();
_resReponseQuestionMasterModel.CreatedDate = System.DateTime.Now;
_resReponseQuestionMasterModel.Active = 1;
_resReponseQuestionMasterModel.CreatedBy = DomainID;
if (addQuestionMasterModel.ParentQuestionID_Add.ToString().Length > 0)
_resReponseQuestionMasterModel.FKQID = addQuestionMasterModel.ParentQuestionID_Add;
else
_resReponseQuestionMasterModel.FKQID = 0;
DBQuestionMasterContext.Add(_resReponseQuestionMasterModel);
DBQuestionMasterContext.SaveChanges();
responseAddQuestion = "Total : " + " " + totalquestions + " " + " Questions are successfully registered.";
}
else
{
responseAddQuestion = "Minimum one question is required.";
}
else
{
}
catch (Exception err)
{
}
return responseAddQuestion;
}
}
[ApiController]
[ServiceFilter(typeof(CustomAuthorization))]
public class QuestionMasterController : ControllerBase
{
private ConfigServerData configServer;
public QuestionMasterController(IOptionsSnapshot
{
configServer = config.Value;
if (!string.IsNullOrEmpty(configServer.Database))
Startup.ConnectionString = configServer.Database;
}
[Route("AddAdminQuestionMaster")]
[HttpPost]
public IActionResult Add(AddCPQuestionMasterModel ReqQuestionMaster)
{
Response responseAdd = new Response();
try
{
responseAdd.Message = new DAL.CPQuestionMaster(configServer,Request).AddMainQuestion(ReqQuestionMaster);
responseAdd.Code = (int)HttpStatusCode.OK;
}
catch (Exception ex)
{
throw new CustomException(ex.Message, ex);
}
return StatusCode(responseAdd.Code, responseAdd);
}
-----------
Sachin SinghPosted Nov 20, 2020, 2:34 PM