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());
        }
Example #2
0
        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}" }));
            }
        }
Example #3
0
        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));
        }
Example #4
0
        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();
        }