public JsonResult EditSection(EditSectionViewModel model) { try { if ("colour".Equals(model.BackgroundType, StringComparison.OrdinalIgnoreCase)) { _sectionService.EditBackgroundType(model.SectionId, false); if (!string.IsNullOrWhiteSpace(model.BackgroundColour)) { _sectionService.EditBackgroundColour(model.SectionId, model.BackgroundColour); } } else { _sectionService.EditBackgroundType(model.SectionId, true); if (model.BackgroundImageId > 0) { _sectionService.EditBackgroundImage(model.SectionId, model.BackgroundImageId); } _sectionService.EditBackgroundStyle(model.SectionId, model.PageSectionBackgroundStyle); } _sectionService.EditHeight(model.SectionId, model.PageSectionHeight); _associationService.EditRoles(model.PageAssociationId, model.SelectedRoleList); return(Json(new { State = true, SectionMarkup = _sectionService.Get(model.SectionId).PageSectionBody })); } catch (Exception) { return(Json(new { State = false })); } }
public ActionResult EditSection(int pageAssociationId) { var pageAssociation = _associationService.Get(pageAssociationId); var pageSection = _sectionService.Get(pageAssociation.PageSection.PageSectionId); var model = new EditSectionViewModel { PageAssociationId = pageAssociationId, SectionId = pageSection.PageSectionId, MediaLibrary = new PaginationViewModel { ImageList = _imageService.Get(), TargetInputField = "BackgroundImageId", PaginationType = "section" }, PageSectionHeight = _sectionService.DetermineSectionHeight(pageSection.PageSectionId), PageSectionBackgroundStyle = _sectionService.DetermineBackgroundStyle(pageSection.PageSectionId), BackgroundType = _sectionService.DetermineBackgroundType(pageSection.PageSectionId), BackgroundColour = _sectionService.DetermineBackgroundColour(pageSection.PageSectionId), RoleList = _roleService.Get(), SelectedRoleList = pageAssociation.PageAssociationRoles.Select(x => x.Role.RoleName).ToList() }; return(View("_EditSection", model)); }
public async Task <IActionResult> Edit(int eventId, int id, EditSectionViewModel model) { var evt = await _dbContext.Events.FindAsync(eventId); if (evt == null) { // TODO: Diplay error return(RedirectToAction("Index", "Events")); } var section = await _dbContext.Sections.FindAsync(id); if (section == null || section.EventId != eventId) { return(RedirectToAction("Details", "Events", new { slug = evt.Slug })); } if (model.StartOn < evt.StartOn || model.StartOn > evt.EndOn) { ModelState.AddModelError(nameof(model.StartOn), "Must be during event times"); } if (model.EndOn < evt.StartOn || model.EndOn > evt.EndOn) { ModelState.AddModelError(nameof(model.EndOn), "Must be during event times"); } if (!ModelState.IsValid) { return(View(model)); } try { section.Name = model.Name; section.Description = model.Description; section.StartOn = model.StartOn; section.EndOn = model.EndOn; await _dbContext.SaveChangesAsync(); return(RedirectToAction("Details", "Events", new { slug = evt.Slug })); } catch (Exception ex) { _logger.LogError(3, ex, "Error updating section"); ModelState.AddModelError("", "There was an error updating the section. Try again."); return(View(model)); } }
public async Task <IActionResult> Edit(long id, [FromBody] EditSectionViewModel vm) { var section = await _sectionsRepository.GetByIdAsync(id); if (section != null) { section.Name = vm.Name; await _sectionsRepository.UpdateAsync(section); return(Ok()); } return(BadRequest()); }
public IActionResult Edit(EditSectionViewModel model) { if (ModelState.IsValid) { Section section = db.Sections.FirstOrDefault(t => t.Id == model.Id); if (section != null) { section.Name = model.Name; db.Sections.Update(section); db.SaveChanges(); } } return(View(model)); }
public async Task <IActionResult> Index() { EditSectionViewModel model = new EditSectionViewModel() { Units = await db.Units.ToListAsync(), TypeSections = await db.TypeSections.ToListAsync(), Sections = await db.Sections.ToListAsync(), SubSections = await db.SubSections.ToListAsync(), SubSection1s = await db.SubSection1s.ToListAsync(), DataYears = await db.DataYears.ToListAsync(), }; return(View(model)); }
public IActionResult Index() { var viewModel = new EditSectionViewModel { AllSections = this.editSectionService.GetAllSections(), }; var model = new EditSectionBaseModel { EditSectionInputModel = new EditSectionInputModel(), EditSectionViewModel = viewModel, }; return(this.View(model)); }
public async Task <IActionResult> CreateUnit(EditSectionViewModel model) { Unit unit = await db.Units.FirstOrDefaultAsync(u => u.Name == model.Name); if (unit == null) { Unit _unit = new Unit() { Name = model.Name }; db.Units.Add(_unit); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(NotFound()); }
public async Task <IActionResult> CreateDataYear(EditSectionViewModel model) { DataYear dataYear = await db.DataYears.FirstOrDefaultAsync(u => u.Name == model.Name); if (dataYear == null) { DataYear _dataYear = new DataYear() { Name = model.Name }; db.DataYears.Add(_dataYear); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(NotFound()); }
public async Task <IActionResult> CreateSection(EditSectionViewModel model) { Section Section = await db.Sections.FirstOrDefaultAsync(u => u.Name == model.Name); if (Section == null) { Section _Section = new Section() { Name = model.Name }; db.Sections.Add(_Section); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(NotFound()); }
public async Task <IActionResult> CreateSubSection1(EditSectionViewModel model) { SubSection1 subSection1 = await db.SubSection1s.FirstOrDefaultAsync(sub => sub.Name == model.Name); if (subSection1 == null) { SubSection1 _subSection1 = new SubSection1() { Name = model.Name, SubSectionId = model.id }; db.SubSection1s.Add(_subSection1); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(NotFound()); }
public async Task <IActionResult> Create(int eventId) { var evt = await _dbContext.Events.FindAsync(eventId); if (evt == null) { // TODO: Diplay error return(RedirectToAction("Index", "Events")); } var model = new EditSectionViewModel(); model.EventId = evt.Id; model.EventName = evt.Name; model.StartOn = evt.StartOn; model.EndOn = evt.StartOn; return(View(model)); }
public IActionResult Edit(int id) { Section section = db.Sections.FirstOrDefault(t => t.Id == id); if (section == null) { return(NotFound()); } EditSectionViewModel model = new EditSectionViewModel { Id = section.Id, Name = section.Name }; List <string> list = new List <string>(); foreach (Test test in db.Tests) { list.Add(test.Name); } ViewBag.Tests = list; db.SaveChanges(); return(View(model)); }
public async Task <JsonResult> EditSection(EditSectionViewModel model) { try { if ("colour".Equals(model.BackgroundType, StringComparison.OrdinalIgnoreCase)) { await _sectionService.EditBackgroundTypeAsync(model.SectionId, false); if (!string.IsNullOrWhiteSpace(model.BackgroundColour)) { await _sectionService.EditBackgroundColourAsync(model.SectionId, model.BackgroundColour); } } else { await _sectionService.EditBackgroundTypeAsync(model.SectionId, true); if (model.BackgroundImageId > 0) { var selectedBackgroundImage = await _imageService.GetAsync(model.BackgroundImageId); await _sectionService.EditBackgroundImageAsync(model.SectionId, selectedBackgroundImage.CDNImagePath(), selectedBackgroundImage.ImageCategory); } await _sectionService.EditBackgroundStyleAsync(model.SectionId, model.PageSectionBackgroundStyle); } await _sectionService.EditHeightAsync(model.SectionId, model.PageSectionHeight); await _associationService.EditRolesAsync(model.PageAssociationId, model.SelectedRoleList); var pageSection = await _sectionService.GetAsync(model.SectionId); return(Json(new { State = true, SectionMarkup = pageSection.PageSectionBody })); } catch (Exception) { return(Json(new { State = false })); } }