public async Task <IActionResult> AddSection(Section objSection) { if (ModelState.IsValid) { Section newSection = new Section { Section_Name = objSection.Section_Name.ToUpper() }; int result = await _SectionRepository.AddSection(newSection); if (result == 1) { TempData["Success"] = "Section Added Successfully"; return(RedirectToAction("Index", "section", new { area = "admin" })); } else { TempData["Error"] = "Section Added Failed"; return(RedirectToAction("Index", "section", new { area = "admin" })); } } return(View()); }
public HttpResponseMessage CreateSection([FromBody] SectionViewModel model) { try { var data = sectionrepository.AddSection(model); if (data != null) { return(Request.CreateResponse(HttpStatusCode.OK, new { success = true, result = model, message = "The record has been created successfully" })); } return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, message = "There was an error creating this message" })); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.OK, new { success = false, message = $"There was an error creating this message {e.Message}" })); } }
public async Task <IActionResult> Post(SectionDtoForAdd section) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (await _repo.SectionExists(section.SectionName)) { return(BadRequest(new { message = "Section Already Exist" })); } var createdObj = await _repo.AddSection(section); return(Ok(_response)); }
public void Restore(string json) { var sections = JsonConvert.DeserializeObject <IEnumerable <Section> >(json); foreach (var section in repo.GetAllSections()) { repo.DeleteSection(section); } repo.Save(); foreach (var section in sections) { repo.AddSection(section); } repo.Save(); }