Example #1
0
        public void AddSize(SizeDto sizeDto, long restaurantAdminId)
        {
            var restaurant = _restaurantService.GetRestaurantByAdminId(restaurantAdminId);

            if (restaurant == null)
            {
                throw new NotFoundException(ErrorCodes.RestaurantNotFound);
            }
            if (restaurant.IsDeleted)
            {
                throw new ValidationException(ErrorCodes.RestaurantDeleted);
            }
            ValidateSize(sizeDto, restaurantAdminId);
            var size = new Size();

            foreach (var sizeName in sizeDto.SizeNameDictionary)
            {
                size.SizeTranslations.Add(new SizeTranslation
                {
                    SizeName = sizeName.Value,
                    Language = sizeName.Key.ToLower()
                });
            }
            size.RestaurantId = restaurant.RestaurantId;
            _sizeTranslationService.InsertRange(size.SizeTranslations);
            _sizeService.Insert(size);
            SaveChanges();
        }
Example #2
0
        public SizeDto UpdateSize(SizeDto sizeDto)
        {
            var size = _mapper.Map <Size>(sizeDto);
            int res  = _repo.Update(size);

            if (res <= 0)
            {
                return(null);
            }
            return(sizeDto);
        }
 public ApiResponse CreateSize([FromBody] SizeDto dto)
 {
     try
     {
         var size = _mapper.Map <Size>(dto);
         _sizeService.AddAsync(size);
         return(new ApiResponse("Add size success", 200));
     }catch (Exception ex)
     {
         return(new ApiResponse("Can't add size", ex, 400));
     }
 }
Example #4
0
        public async Task <IActionResult> AddSize(SizeDto sizeDto)
        {
            var size = new Size
            {
                Name  = sizeDto.Name,
                Price = sizeDto.Price
            };

            await _context.Size.AddAsync(size);

            await _context.SaveChangesAsync();

            return(StatusCode(201));
        }
Example #5
0
        public void SaveSizesToDb(SizeDto sizeDto)
        {
            // var sizeItem=_mapper.Map<Size>(sizeDto);


            var item = _appDbContext.Sizes.Where(a => a.Id == sizeDto.Id).FirstOrDefault();

            if (item != null)
            {
                //TODO:Make it not string in the db
                item.Name  = sizeDto.Name;
                item.Price = sizeDto.Price;
            }

            _appDbContext.SaveChanges();
        }
Example #6
0
        public async Task <IActionResult> EditSize(SizeDto sizeDto, int id)
        {
            var size = await _context.Size.FirstOrDefaultAsync(x => x.Id == id);

            if (size == null)
            {
                return(null);
            }

            size.Name  = sizeDto.Name;
            size.Price = sizeDto.Price;

            await _context.SaveChangesAsync();

            return(StatusCode(200));
        }
        public ActionResult <SizeDto> CreateSize([FromBody] SizeDto size)
        {
            var sizeDto = _sizeService.CreateSize(size);

            if (sizeDto == null)
            {
                List <string> errorMessage = new List <string>();
                errorMessage.Add("Đã phát sinh lỗi, vui lòng thử lại");
                return(BadRequest(new ResponseDto(errorMessage, 500, sizeDto)));
            }
            List <string> successMessage = new List <string>();

            successMessage.Add("Thêm thông tin thành công");
            var responseDto = new ResponseDto(successMessage, 200, sizeDto);

            return(Ok(responseDto));
        }
Example #8
0
        public void UpdateSize(SizeDto sizeDto, long restaurantAdminId)
        {
            var restaurant = _restaurantService.GetRestaurantByAdminId(restaurantAdminId);

            if (restaurant == null)
            {
                throw new NotFoundException(ErrorCodes.RestaurantNotFound);
            }
            if (restaurant.IsDeleted)
            {
                throw new ValidationException(ErrorCodes.RestaurantDeleted);
            }
            var size = _sizeService.Find(sizeDto.SizeId);

            if (size == null)
            {
                throw new NotFoundException(ErrorCodes.SizeNotFound);
            }
            ValidateSize(sizeDto, restaurantAdminId);
            foreach (var sizeName in sizeDto.SizeNameDictionary)
            {
                var sizeTranslation =
                    size.SizeTranslations.FirstOrDefault(x => x.Language.ToLower() == sizeName.Key.ToLower());
                if (sizeTranslation == null)
                {
                    size.SizeTranslations.Add(new SizeTranslation
                    {
                        Language = sizeName.Key.ToLower(),
                        SizeName = sizeName.Value
                    });
                }
                else
                {
                    sizeTranslation.SizeName = sizeName.Value;
                }
            }
            size.RestaurantId = restaurant.RestaurantId;
            _sizeService.Update(size);
            SaveChanges();
        }
Example #9
0
 private void ValidateSize(SizeDto sizeDto, long restaurantAdminId)
 {
     foreach (var sizeName in sizeDto.SizeNameDictionary)
     {
         if (string.IsNullOrEmpty(sizeName.Value))
         {
             throw new ValidationException(ErrorCodes.EmptySizeName);
         }
         if (sizeName.Value.Length > 100)
         {
             throw new ValidationException(ErrorCodes.SizeNameExceedLength);
         }
         if (sizeName.Value.Length < 3)
         {
             throw new ValidationException(ErrorCodes.SizeNameMinimumLength);
         }
         if (_sizeTranslationService.CheckSizeNameExist(sizeName.Value, sizeName.Key, sizeDto.SizeId,
                                                        restaurantAdminId))
         {
             throw new ValidationException(ErrorCodes.SizeNameAlreadyExist);
         }
     }
 }
        private async Task <SizeTypeEntity> GetOrCreateSizeAsync(SizeDto sizeDto)
        {
            var sizeDb =
                await Db.SizeTypeEntities.FirstOrDefaultAsync(x => sizeDto.RussianSize == x.RussianSize &&
                                                              sizeDto.OtherCountry == x.OtherCountry &&
                                                              sizeDto.CountryCode == x.CountryCode);

            if (sizeDb != null)
            {
                return(sizeDb);
            }

            sizeDb = new SizeTypeEntity
            {
                CountryCode  = sizeDto.CountryCode,
                OtherCountry = sizeDto.OtherCountry,
                RussianSize  = sizeDto.RussianSize
            };
            Db.SizeTypeEntities.Add(sizeDb);
            await Db.SaveChangesAsync();

            return(sizeDb);
        }
Example #11
0
        public ActionResult Update(SizeDto dto)
        {
            var result = _sizeContract.Update(dto);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }