public async Task <IActionResult> UpdateByPageSections([FromBody] PLPageSection[] plPageSections) { if (plPageSections == null) { return(_exceptionHandler.HandleException(new ArgumentNullException("plPageSections was null. Most likely the received data was not in the right format."), isServerSideException: false)); } if (plPageSections.Length == 0) { return(_exceptionHandler.HandleException(new ArgumentException("No page sections were received. There is nothing to update. Only send filled page sections"), isServerSideException: false)); } foreach (var pageSection in plPageSections) { if (pageSection.PLSectionParts.Count == 0) { return(_exceptionHandler.HandleException(new ArgumentException("No sections part were found in one of the page sections. There is nothing to update. Only send filled page sections."), isServerSideException: false)); } } IBLPageSection[] blPageSections = new DALPageSection[plPageSections.Length]; for (int i = 0; i < plPageSections.Length; i++) { ICollection <IBLSectionPart> sectionParts = new List <IBLSectionPart>(); foreach (IPLSectionPart plSectionPart in plPageSections[i].PLSectionParts) { sectionParts.Add ( new DALSectionPart { SectionPartId = plSectionPart.SectionPartId, PageSectionFK = plPageSections[i].PageSectionId, Type = plSectionPart.Type, Content = plSectionPart.Content } ); } blPageSections[i] = new DALPageSection { PageSectionId = plPageSections[i].PageSectionId, PageRoute = plPageSections[i].PageRoute, Parts = sectionParts }; } try { await _editPageAdapter.UpdateByPageSectionsAsync(blPageSections); } catch (Exception ex) { return(_exceptionHandler.HandleException(ex, isServerSideException: true)); } return(Ok()); }
public async Task <IBLPageSection> ReadByIdAsync(string id) { if (String.IsNullOrEmpty(id)) { throw new ArgumentException("Parameters id cannot be null or empty"); } var guid = new Guid(id); DALPageSection dalPageSection = await _dbContext.PageSections.FirstOrDefaultAsync(ps => ps.PageSectionId == guid); if (dalPageSection == null) { throw new Exception("No UserAccount was found matching this id"); } return(dalPageSection); }