Exemplo n.º 1
0
        public bool AddRestaurantType(RestaurantTypeDto restaurantTypeDto, long userId)
        {
            ValidateRestaurantType(restaurantTypeDto);
            RestaurantType restaurantType = new RestaurantType();

            restaurantType.RestaurantTypeId           = _restaurantTypeService.GetLastRecordId() + 1;
            restaurantType.RestaurantTypeTranslations = new List <RestaurantTypeTranslation>();
            //foreach (var type in restaurantTypeDto.TypeName)
            //{

            foreach (var typeName in restaurantTypeDto.TypeNameDictionary)
            {
                if (_restaurantTypeTranslationService.CheckRepeatedType(typeName.Value, typeName.Key,
                                                                        restaurantType.RestaurantTypeId, userId))
                {
                    throw new ValidationException(ErrorCodes.RestaurantTypeAlreadyExist);
                }

                restaurantType.RestaurantTypeTranslations.Add(new RestaurantTypeTranslation
                {
                    Language         = typeName.Key.ToLower(),
                    TypeName         = typeName.Value,
                    RestaurantTypeId = restaurantType.RestaurantTypeId
                });
            }

            //}
            restaurantType.AdminId = userId;
            _restaurantTypeTranslationService.InsertRange(restaurantType.RestaurantTypeTranslations);
            _restaurantTypeService.Insert(restaurantType);
            SaveChanges();
            return(true);
        }
Exemplo n.º 2
0
 private void ValidateRestaurantType(RestaurantTypeDto restaurantTypeDto)
 {
     foreach (var typeName in restaurantTypeDto.TypeNameDictionary)
     {
         if (string.IsNullOrEmpty(typeName.Value))
         {
             throw new ValidationException(ErrorCodes.EmptyRestaurantType);
         }
         if (typeName.Value.Length > 300)
         {
             throw new ValidationException(ErrorCodes.RestaurantTypeExceedLength);
         }
         if (Strings.SupportedLanguages.All(x => x.ToLower() != typeName.Key.ToLower()))
         {
             throw new ValidationException(ErrorCodes.UnSupportedLanguage);
         }
     }
 }
Exemplo n.º 3
0
        public void UpdateRestaurantType(RestaurantTypeDto restaurantTypeDto, long userId)
        {
            ValidateRestaurantType(restaurantTypeDto);
            var restaurantType = _restaurantTypeService.Find(restaurantTypeDto.RestaurantTypeId);

            if (restaurantType == null)
            {
                throw new NotFoundException(ErrorCodes.RestaurantTypeNotFound);
            }
            foreach (var typeName in restaurantTypeDto.TypeNameDictionary)
            {
                if (_restaurantTypeTranslationService.CheckRepeatedType(typeName.Value, typeName.Key,
                                                                        restaurantType.RestaurantTypeId, userId))
                {
                    throw new ValidationException(ErrorCodes.RestaurantTypeAlreadyExist);
                }
                var restaurantTypeTranslation =
                    restaurantType.RestaurantTypeTranslations.FirstOrDefault(
                        x => x.Language.ToLower() == typeName.Key.ToLower());
                if (restaurantTypeTranslation != null)
                {
                    restaurantTypeTranslation.TypeName = typeName.Value;
                }
                else
                {
                    restaurantType.RestaurantTypeTranslations.Add(new RestaurantTypeTranslation
                    {
                        Language         = typeName.Key.ToLower(),
                        TypeName         = typeName.Value,
                        RestaurantTypeId = restaurantType.RestaurantTypeId
                    });
                }
            }
            _restaurantTypeService.Update(restaurantType);
            SaveChanges();
        }