示例#1
0
        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));
        }
示例#2
0
        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));
        }
示例#3
0
        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));
        }