Пример #1
0
        public IActionResult RestaurantTypeEdit(RestaurantTypeEditViewModel model)
        {
            RestaurantType type = new RestaurantType
            {
                Naam = model.Naam
            };

            _service.Update(type, model.Id);
            return(RedirectToAction("RestaurantTypeList"));
        }
Пример #2
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();
        }