//add of update page and return its ID we need id of newly created page in updation call,otherwise we will public async Task <string> InsertOrUpdateCMSContent(CustomPageDto input) { if (input.Id > 0) // updation case, check if page exist first { var pageExists = await _CustomPageRepository.GetAll().AnyAsync(c => c.Id == input.Id); if (!pageExists) { throw new EntityNotFoundException(typeof(CustomPage), input.Id); } } var TitleExisits = await _CustomPageRepository.GetAll().AnyAsync(c => c.Title == input.Title && c.Id != input.Id); if (TitleExisits) { return("Page with this title already exist."); } var config = new MapperConfiguration(cfg => cfg.CreateMap <CustomPageDto, CustomPage>()); var mapper = config.CreateMapper(); var page = mapper.Map <CustomPage>(input); var pageId = await _CustomPageRepository.InsertOrUpdateAndGetIdAsync(page); return(pageId.ToString()); }
// Map CustomPage entity to CustomPage Dto // AutoMapper can also be used instead of this private CustomPageDto MapToDto(CustomPage page) { CustomPageDto customPageDto = new CustomPageDto(); customPageDto.Id = page.Id; customPageDto.Title = page.Title; customPageDto.Content = page.Content; return(customPageDto); }