public async Task <List <FoodMenuSubScreenForReturnDto> > GetListAsync() { var getListFromRepo = await foodMenuSubScreenDal.GetListAsync(); if (getListFromRepo == null) { throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFound }); } return(mapper.Map <List <FoodMenuSubscreen>, List <FoodMenuSubScreenForReturnDto> >(getListFromRepo)); }
public async Task <FoodMenuForReturnDto> Publish(FoodMenuForCreationDto updateDto) { var checkFromRepo = await foodMenuDal.GetAsync(x => x.Id == updateDto.Id); if (checkFromRepo == null) { throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.NotFound }); } var checkHomeAnnounceSubScreenForPublish = await foodMenuSubScreenDal.GetListAsync(x => x.FoodMenuId == updateDto.Id); if (checkHomeAnnounceSubScreenForPublish.Count <= 0) { throw new RestException(HttpStatusCode.BadRequest, new { NotSelectSubScreen = Messages.NotSelectSubScreen }); } if (updateDto.IsPublish) { var checkDateExpire = DateTime.Compare(DateTime.Now, checkFromRepo.PublishFinishDate); if (checkDateExpire > 0) { throw new RestException(HttpStatusCode.BadRequest, new { NotFound = Messages.PublishDateExpire }); } } var mapForUpdate = mapper.Map(updateDto, checkFromRepo); mapForUpdate.Updated = DateTime.Now; mapForUpdate.AnnounceType = "foodmenu"; await foodMenuDal.Update(mapForUpdate); var spec = new FoodMenuWithUserSpecification(updateDto.Id); var getAnnounceWithUserFromRepo = await foodMenuDal.GetEntityWithSpecAsync(spec); return(mapper.Map <FoodMenu, FoodMenuForReturnDto>(getAnnounceWithUserFromRepo)); }