Example #1
0
        public async Task <FoodMenuForKiosksToReturnDto> GetFoodMenuById(int foodMenuId)
        {
            var spec     = new FoodMenuWithUserSpecification(foodMenuId);
            var foodMenu = await foodMenuDal.GetEntityWithSpecAsync(spec);

            return(mapper.Map <FoodMenu, FoodMenuForKiosksToReturnDto>(foodMenu));
        }
Example #2
0
        public async Task <FoodMenuForReturnDto> Create(FoodMenuForCreationDto creationDto)
        {
            var claimId = int.Parse(httpContextAccessor.HttpContext.User?.Claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value);


            var mapForCreate = mapper.Map <FoodMenu>(creationDto);
            var slideId      = Guid.NewGuid();

            mapForCreate.SlideId      = slideId;
            mapForCreate.UserId       = claimId;
            mapForCreate.Created      = DateTime.Now;
            mapForCreate.AnnounceType = "foodmenu";

            var createAnnounce = await foodMenuDal.Add(mapForCreate);

            var spec = new FoodMenuWithUserSpecification(createAnnounce.Id);

            var getAnnounceFromRepo = await foodMenuDal.GetEntityWithSpecAsync(spec);

            if (getAnnounceFromRepo == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { AlreadyExist = Messages.NotFound });
            }
            return(mapper.Map <FoodMenu, FoodMenuForReturnDto>(getAnnounceFromRepo));
        }
Example #3
0
        public async Task <FoodMenuForReturnDto> Update(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 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));
        }
Example #4
0
        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));
        }