public ResponseModel <List <ExamStatusModel> > ExamStatusList() { ResponseModel <List <ExamStatusModel> > result = new ResponseModel <List <ExamStatusModel> > { Data = new List <ExamStatusModel>() }; try { var lst = _context.ExamStatuses.Where(x => x.IsActive == true); foreach (var item in lst) { ExamStatusModel model = new ExamStatusModel(); model.Id = item.Id; model.Name = item.Name; model.IsActive = item.IsActive; result.Data.Add(model); } result.status = true; result.message = "success"; } catch (Exception ex) { result.message = ex.Message; } return(result); }
public ResponseModel <ExamStatusModel> Update(ExamStatusModel model) { ResponseModel <ExamStatusModel> result = new ResponseModel <ExamStatusModel> { Data = new ExamStatusModel() }; try { var item = _context.ExamStatuses.Where(e => e.Id == model.Id).Select(e => e).FirstOrDefault(); if (item != null) { item.Name = model.Name; //item.IsActive = model.IsActive; _context.SaveChanges(); result = new ResponseModel <ExamStatusModel> { status = true, message = "Success" }; } else { result = new ResponseModel <ExamStatusModel> { status = false, message = "Status Not Found" }; } } catch (Exception ex) { result = new ResponseModel <ExamStatusModel> { status = false, message = ex.Message.ToString() }; } return(result); }
public ResponseModel <ExamStatusModel> Save(ExamStatusModel model) { ResponseModel <ExamStatusModel> result = new ResponseModel <ExamStatusModel> { Data = new ExamStatusModel() }; try { ExamStatuses db = new ExamStatuses(); db.Name = model.Name; db.IsActive = true; _context.ExamStatuses.Add(db); _context.SaveChanges(); result = new ResponseModel <ExamStatusModel> { status = true, message = "Success", Data = new ExamStatusModel() { Id = db.Id, Name = db.Name } }; } catch (Exception ex) { result.status = false; result.message = ex.Message; result.Data = new ExamStatusModel() { Id = 0, Name = null }; } return(result); }
// PUT api/<controller>/5 public IActionResult Update([FromBody] ExamStatusModel model) { var result = examStatusManager.Update(model); if (result.status) { return(Ok(result.message)); } else { return(BadRequest(result.message)); } }
public IActionResult Save([FromBody] ExamStatusModel model) { var result = examStatusManager.Save(model); if (result.status) { return(Ok(new { TestId = result.Data.Id, TestTitle = result.Data.Name })); } else { return(BadRequest(result.message)); } }
// [ValidateInput(false)] public ActionResult Create(ExamStatusModel examModel) { ResponseModel <ExamStatusModel> result = null; if (examModel.Id == 0) { result = examStatus.Save(examModel); } else { result = examStatus.Update(examModel); } if (result.status) { return(RedirectToAction("Index")); } else { ViewBag.ErrorMessage = result.message; return(View("Error")); } }
public IActionResult Update(ExamStatusModel model) { return(Json("")); }