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);
        }
Exemple #2
0
        public IActionResult RestaurantTypeCreate(RestaurantTypeCreateViewModel model)
        {
            RestaurantType restaurantType = new RestaurantType
            {
                Naam = model.Naam
            };

            _service.Insert(restaurantType);
            return(RedirectToAction("RestaurantTypeList"));
        }