public APIResponse UpdateQuestionBank(QuestionBankDetail questionsDetailsView) { APIResponse response = new APIResponse(); dateTime = DateTime.UtcNow.AddHours(5).AddMinutes(30); response.Result = false; try { using (DBEntities testEngineEntities = new DBEntities()) { var data = testEngineEntities.QuestionBankMasters.Where(x => x.ID == questionsDetailsView.ID && x.IsDeleted == false).FirstOrDefault(); if (data != null) { data.QuestionBankDescription = questionsDetailsView.Description; data.Duration = questionsDetailsView.Duration; data.QuestionBankName = questionsDetailsView.QuestionBankName; data.ModifiedDate = dateTime; testEngineEntities.SaveChanges(); response.Result = true; } } } catch (Exception ex) { throw ex; } return(response); }
public APIResponse UploadQuestionBank(QuestionBankDetail questionsDetailsData) { APIResponse aPIResponse = new APIResponse(); QuestionBankBLL questionBankBLL = new QuestionBankBLL(); aPIResponse = questionBankBLL.QuestionBankUpload(questionsDetailsData); return(aPIResponse); }
public APIResponse QuestionBankUpload(QuestionBankDetail questionsDetailsData) { List <QuestionsDetailsView> QuestionsDetailsView = new List <QuestionsDetailsView>(); APIResponse aPIResponse = new APIResponse(); dateTime = DateTime.UtcNow.AddHours(5).AddMinutes(30); aPIResponse.Result = false; try { using (DBEntities testEngineEntities = new DBEntities()) { QuestionBankMaster questionBankMaster = new QuestionBankMaster(); questionBankMaster.ID = Guid.NewGuid(); questionBankMaster.QuestionBankName = questionsDetailsData.QuestionBankName; questionBankMaster.CreatedDate = dateTime;; questionBankMaster.Duration = questionsDetailsData.Duration; questionBankMaster.IsActive = true; questionBankMaster.IsDeleted = false; questionBankMaster.ModifiedDate = dateTime;; questionBankMaster.QuestionBankDescription = questionsDetailsData.Description; testEngineEntities.QuestionBankMasters.Add(questionBankMaster); foreach (var item in questionsDetailsData.questionsDetailsViews) { bool IsMaster = false; QuestionsDetail questionsDetails = new QuestionsDetail(); questionsDetails.Answer = item.Answer; questionsDetails.CreatedDate = dateTime;; questionsDetails.ID = Guid.NewGuid(); questionsDetails.IsDeleted = false; questionsDetails.ModifiedDate = dateTime;; questionsDetails.OptionA = item.OptionA; questionsDetails.OptionB = item.OptionB; questionsDetails.OptionC = item.OptionC; questionsDetails.OptionD = item.OptionD; questionsDetails.OptionE = item.OptionE; questionsDetails.MasterQuestion = item.MasterQuestion; questionsDetails.Question = item.Question; questionsDetails.QuestionBankID = questionBankMaster.ID; if (!string.IsNullOrEmpty(item.MasterQuestion)) { IsMaster = true; } questionsDetails.IsMaster = IsMaster; testEngineEntities.QuestionsDetails.Add(questionsDetails); } testEngineEntities.SaveChanges(); aPIResponse.Result = true; } } catch (Exception ex) { throw ex; } return(aPIResponse); }
public APIResponse UpdateQuestionBank(QuestionBankDetail questionsDetails) { APIResponse aPIResponse = new APIResponse(); QuestionBankDAL questionBankDAL = new QuestionBankDAL(); aPIResponse = questionBankDAL.UpdateQuestionBank(questionsDetails); return(aPIResponse); }
public APIResponse UpdateQuestionBank(QuestionBankDetail questionsDetailsView) { try { APIResponse = objQuestionBank.UpdateQuestionBank(questionsDetailsView); } catch (Exception ex) { throw; } return(APIResponse); }
public QuestionBankDetail QuestionsBankEdit(Guid?QuestionBankId) { QuestionBankDetail questionBankDetail = new QuestionBankDetail(); try { questionBankDetail = objQuestionBank.QuestionsBankEdit(QuestionBankId); } catch (Exception ex) { throw; } return(questionBankDetail); }
public ActionResult UpdateQuestionBank(QuestionBankDetail questionsDetailsView) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(apiUrl); var result = client.PostAsJsonAsync(apiUrl + "/QuestionBank/UpdateQuestionBank", questionsDetailsView).Result; if (result.IsSuccessStatusCode) { var Result = result.Content.ReadAsStringAsync().Result; APIResponse = JsonConvert.DeserializeObject <APIResponse>(Result); } } return(Json(APIResponse, JsonRequestBehavior.AllowGet)); }
public ActionResult QuestionsBankEdit(Guid?QuestionBankId) { QuestionBankDetail questionsDetailsView = new QuestionBankDetail(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(apiUrl); var result = client.GetAsync(apiUrl + "/QuestionBank/QuestionsBankEdit?QuestionBankId=" + QuestionBankId).Result; if (result.IsSuccessStatusCode) { var Result = result.Content.ReadAsStringAsync().Result; questionsDetailsView = JsonConvert.DeserializeObject <QuestionBankDetail>(Result); } } return(Json(questionsDetailsView, JsonRequestBehavior.AllowGet)); }
public QuestionBankDetail QuestionsBankEdit(Guid?QuestionBankId) { QuestionBankDetail detail = new QuestionBankDetail(); try { var data = objQuestion.QuestionsBankEdit(QuestionBankId); detail.ID = data.ID; detail.Description = data.QuestionBankDescription; detail.Duration = data.Duration; detail.QuestionBankName = data.QuestionBankName; } catch (Exception) { throw; } return(detail); }
public List <QuestionBankDetail> GetExistingQuestionBank() { List <QuestionBankDetail> QuestionBankDetail = new List <QuestionBankDetail>(); var QuestionBankData = objQuestion.GetQuestionBank(); if (QuestionBankData.Count > 0) { QuestionBankData.ForEach(x => { QuestionBankDetail detail = new QuestionBankDetail(); detail.Description = x.QuestionBankDescription; detail.Duration = x.Duration; detail.QuestionBankName = x.QuestionBankName; detail.ID = x.ID; QuestionBankDetail.Add(detail); }); } return(QuestionBankDetail); }
public ActionResult UploadQuestionBank(string QuestionBankName, string Duration, string Description, bool Status) { string Result = "Failed"; foreach (string file in Request.Files) { HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase; string fileextension = Path.GetExtension(hpf.FileName); var questionBankDetail = new QuestionBankDetail(); if (fileextension == ".xlsx" || fileextension == ".xls" || fileextension == ".csv") { var dt = Common.ConvertFileToDateTable(hpf, "QuestionUploadFile"); List <QuestionsDetailsView> questionsDetailsView = new List <QuestionsDetailsView>(); var rowCount = dt.Rows.Count; for (int i = 0; i < rowCount; i++) { QuestionsDetailsView questionDetail = new QuestionsDetailsView(); string Question = dt.Rows[i]["Question"] != DBNull.Value ? dt.Rows[i]["Question"].ToString().Trim().ToUpper() : string.Empty; questionDetail.Question = Question; string OptionA = dt.Rows[i]["OptionA"] != DBNull.Value ? dt.Rows[i]["OptionA"].ToString().Trim().ToUpper() : string.Empty; questionDetail.OptionA = OptionA; string OptionB = dt.Rows[i]["OptionB"] != DBNull.Value ? dt.Rows[i]["OptionB"].ToString().Trim().ToUpper() : string.Empty; questionDetail.OptionB = OptionB; string OptionC = dt.Rows[i]["OptionC"] != DBNull.Value ? dt.Rows[i]["OptionC"].ToString().Trim().ToUpper() : string.Empty; questionDetail.OptionC = OptionC; string OptionD = dt.Rows[i]["OptionD"] != DBNull.Value ? dt.Rows[i]["OptionD"].ToString().Trim().ToUpper() : string.Empty; questionDetail.OptionC = OptionD; string Answer = dt.Rows[i]["Answer"] != DBNull.Value ? dt.Rows[i]["Answer"].ToString().Trim().ToUpper() : string.Empty; questionDetail.Answer = Answer; if (questionDetail != null) { questionsDetailsView.Add(questionDetail); } } if (questionsDetailsView.Any()) { using (var client = new HttpClient()) { questionBankDetail.Description = Description; questionBankDetail.QuestionBankName = QuestionBankName; questionBankDetail.Status = Status; questionBankDetail.Duration = new TimeSpan(0, 0, 13, 0, 0); client.BaseAddress = new Uri(apiUrl); var jsonSerialiser = new JavaScriptSerializer(); var json = JsonConvert.SerializeObject(questionsDetailsView); var responseTask = client.GetAsync("QuestionBankUpload?QuestionsDetailsView=" + questionsDetailsView); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { } else //web api sent error response { //log response status here.. } } } } } return(Json("")); }
public ActionResult UploadQuestionBank(string QuestionBankName, string Duration, string Description, bool Status) { APIResponse response = new APIResponse(); int duplicates = 0; int NoAnswer = 0; int NoOption = 0; int NoQuestion = 0; int MasterQuestionId = 1000; try { string Result = "Failed"; logger.WriteToLogFile("UploadQuestionBank - Starts"); foreach (string file in Request.Files) { HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase; string fileextension = Path.GetExtension(hpf.FileName); QuestionBankDetail questionBankDetail = new QuestionBankDetail(); questionBankDetail.questionsDetailsViews = new List <QuestionsDetailsView>(); if (fileextension == ".xlsx" || fileextension == ".xls" || fileextension == ".csv") { var dt = Common.ConvertFileToDateTable(hpf, "QuestionUploadFile"); List <QuestionsDetailsView> questionsDetailsView = new List <QuestionsDetailsView>(); var rowCount = dt.Rows.Count; for (int i = 0; i < rowCount; i++) { QuestionsDetailsView questionDetail = new QuestionsDetailsView(); if (!string.IsNullOrEmpty(dt.Rows[i].ItemArray[0].ToString())) { string MasterQuestion = dt.Rows[i]["MasterQuestion"] != DBNull.Value ? dt.Rows[i]["MasterQuestion"].ToString().Trim().ToUpper() : string.Empty; questionDetail.MasterQuestion = MasterQuestion.Trim(); } string Question = dt.Rows[i]["Question"] != DBNull.Value ? dt.Rows[i]["Question"].ToString().Trim().ToUpper() : string.Empty; questionDetail.Question = Question.Trim(); string OptionA = dt.Rows[i]["OptionA"] != DBNull.Value ? dt.Rows[i]["OptionA"].ToString().Trim().ToUpper() : string.Empty; questionDetail.OptionA = OptionA.Trim(); string OptionB = dt.Rows[i]["OptionB"] != DBNull.Value ? dt.Rows[i]["OptionB"].ToString().Trim().ToUpper() : string.Empty; questionDetail.OptionB = OptionB.Trim(); string OptionC = dt.Rows[i]["OptionC"] != DBNull.Value ? dt.Rows[i]["OptionC"].ToString().Trim().ToUpper() : string.Empty; questionDetail.OptionC = OptionC.Trim(); string OptionD = dt.Rows[i]["OptionD"] != DBNull.Value ? dt.Rows[i]["OptionD"].ToString().Trim().ToUpper() : string.Empty; questionDetail.OptionD = OptionD.Trim(); string OptionE = dt.Rows[i]["OptionE"] != DBNull.Value ? dt.Rows[i]["OptionE"].ToString().Trim().ToUpper() : string.Empty; questionDetail.OptionE = OptionE.Trim(); string Answer = dt.Rows[i]["Answer"] != DBNull.Value ? dt.Rows[i]["Answer"].ToString().Trim().ToUpper() : string.Empty; questionDetail.Answer = Answer.Trim(); if (questionDetail != null) { if (questionsDetailsView.Any(x => x.Question.Trim().ToUpper() == questionDetail.Question.Trim().ToUpper())) { duplicates++; } else if (string.IsNullOrEmpty(questionDetail.Answer)) { NoAnswer++; } else if (string.IsNullOrEmpty(questionDetail.OptionA) && string.IsNullOrEmpty(questionDetail.OptionB) && string.IsNullOrEmpty(questionDetail.OptionC) && string.IsNullOrEmpty(questionDetail.OptionD) && string.IsNullOrEmpty(questionDetail.OptionE)) { NoOption++; } else if (string.IsNullOrEmpty(questionDetail.Question)) { NoQuestion++; } else { questionsDetailsView.Add(questionDetail); } } } var duplicateserror = "Duplicates Questions : " + duplicates; var noanserror = "Question without Answer : " + NoAnswer; var nooptionerror = "Question without Option : " + NoOption; var noquestionerror = "Question without Question : " + NoQuestion; var ResultMessage = "Question bank Upload Failed"; var AlertMessages = ""; if (duplicates > 0 && NoAnswer == 0 && NoOption == 0 && NoQuestion == 0) { AlertMessages = " => " + duplicateserror; } else if (duplicates == 0 && NoAnswer > 0 && NoOption == 0 && NoQuestion == 0) { AlertMessages = " => " + noanserror; } else if (duplicates == 0 && NoAnswer == 0 && NoOption > 0 && NoQuestion == 0) { AlertMessages = " => " + nooptionerror; } else if (duplicates == 0 && NoAnswer == 0 && NoOption == 0 && NoQuestion > 0) { AlertMessages = " => " + nooptionerror; } else if (duplicates > 0 && NoAnswer > 0 && NoOption == 0 && NoQuestion == 0) { AlertMessages = " => " + duplicateserror + " || " + noanserror; } else if (duplicates > 0 && NoAnswer == 0 && NoOption > 0 && NoQuestion == 0) { AlertMessages = " => " + duplicateserror + " || " + nooptionerror; } else if (duplicates > 0 && NoAnswer == 0 && NoOption == 0 && NoQuestion > 0) { AlertMessages = " => " + duplicateserror + " || " + noquestionerror; } else if (duplicates == 0 && NoAnswer > 0 && NoOption == 0 && NoQuestion > 0) { AlertMessages = " => " + noanserror + " || " + noquestionerror; } else if (duplicates == 0 && NoAnswer == 0 && NoOption > 0 && NoQuestion > 0) { AlertMessages = " => " + nooptionerror + " || " + noquestionerror; } else if (duplicates > 0 && NoAnswer > 0 && NoOption > 0 && NoQuestion == 0) { AlertMessages = " => " + duplicateserror + " || " + noanserror + " || " + nooptionerror; } else if (duplicates > 0 && NoAnswer > 0 && NoOption == 0 && NoQuestion > 0) { AlertMessages = " => " + duplicateserror + " || " + noanserror + " || " + noquestionerror; } else if (duplicates > 0 && NoAnswer == 0 && NoOption > 0 && NoQuestion > 0) { AlertMessages = " => " + duplicateserror + " || " + nooptionerror + " || " + noquestionerror; } else if (duplicates == 0 && NoAnswer > 0 && NoOption > 0 && NoQuestion > 0) { AlertMessages = " => " + nooptionerror + " || " + noanserror + " || " + noquestionerror; } else if (duplicates > 0 && NoAnswer > 0 && NoOption > 0 && NoQuestion > 0) { AlertMessages = " => " + duplicateserror + " || " + noanserror + " || " + noquestionerror + " || " + nooptionerror; } if (questionsDetailsView.Any()) { questionBankDetail.questionsDetailsViews = questionsDetailsView; using (var client = new HttpClient()) { questionBankDetail.Description = Description; questionBankDetail.QuestionBankName = QuestionBankName; questionBankDetail.Status = Status; var splitData = Duration.Split(':'); int hour = splitData.Length > 0 ? Convert.ToInt32(splitData[0]) : 0; int minutes = splitData.Length > 1 ? Convert.ToInt32(splitData[1]) : 0; int sec = splitData.Length > 2 ? Convert.ToInt32(splitData[2]) : 0; questionBankDetail.Duration = new TimeSpan(hour, minutes, sec); var masterlist = questionBankDetail.questionsDetailsViews.Where(x => !string.IsNullOrEmpty(x.MasterQuestion)).ToList(); questionBankDetail.questionsDetailsViews = questionBankDetail.questionsDetailsViews.Where(x => string.IsNullOrEmpty(x.MasterQuestion)).ToList(); foreach (var items in masterlist) { for (var i = 0; i <= masterlist.Count - 1; i++) { if (items.MasterQuestion == masterlist[i].MasterQuestion) { items.MasterQuestionId = MasterQuestionId; } } MasterQuestionId++; } questionBankDetail.questionsDetailsViews.AddRange(masterlist); if (questionBankDetail.questionsDetailsViews.Count > 0) { client.BaseAddress = new Uri(apiUrl); var result = client.PostAsJsonAsync(apiUrl + "/QuestionBank/UploadQuestionBank", questionBankDetail).Result; if (result.IsSuccessStatusCode) { Result = result.Content.ReadAsStringAsync().Result; response = JsonConvert.DeserializeObject <APIResponse>(Result); ResultMessage = "Question bank Uploaded Succesfully"; } } } } response.Message = ResultMessage + AlertMessages; } } } catch (Exception ex) { logger.WriteToLogFile("UploadQuestionBank - " + ex.ToString()); if (ex.InnerException != null) { logger.WriteToLogFile("UploadQuestionBank InnerException - " + ex.ToString()); } } return(this.Json(new { data = response })); }