public async Task <IActionResult> PutMenuItems(int id, MenuItemsDto menuItemsDto) { if (id != menuItemsDto.Id) { return(BadRequest("Update not allowed")); } var menuItemFromDb = await uow.MenuItemsRepository.findMenuItemsAsync(id); if (menuItemFromDb == null) { return(BadRequest("Update not allowed")); } var linksFromDto = menuItemsDto.Links; menuItemsDto.Links = new List <LinksDto>(); var menuItems = mapper.Map(menuItemsDto, menuItemFromDb); foreach (var link in linksFromDto) { var link1 = uow.LinksRepository.findLinksAsync(link.Id).Result; menuItems.Links.Add(link1); link1.MenuItems.Add(menuItems); } await uow.SaveAsync(); return(StatusCode(200)); }
public async Task <IActionResult> GetStdMenuItems() { var menuitems = new MenuItemsDto { Companies = await uw.CompanyDetailedRepo.GetCompanyDetails(), StandardSurveyTypes = await uw.SurveyTypeRepo.GetAll(), StandardMenuItems = await uw.StandardMenuItemsRepo.GetAll() }; return(Ok(menuitems)); }
public async Task <IActionResult> PostMenuItems(MenuItemsDto menuItemsDto) { var linksFromDto = menuItemsDto.Links; menuItemsDto.Links = new List <LinksDto>(); var menuItems = mapper.Map <MenuItems>(menuItemsDto); uow.MenuItemsRepository.addMenuItems(menuItems); foreach (var link in linksFromDto) { var link1 = uow.LinksRepository.findLinksAsync(link.Id).Result; menuItems.Links.Add(link1); link1.MenuItems.Add(menuItems); } await uow.SaveAsync(); return(StatusCode(201)); }