private async void CreateFoodButton_Click(object sender, EventArgs e)
        {
            if (_isHubConnectionStarted is false)
            {
                await _hubConnection.StartAsync();

                _isHubConnectionStarted = true;
            }

            CreateFoodDto createFoodDto = new CreateFoodDto
            {
                Name        = NameTextBox.Text,
                Description = DescriptionTextBox.Text,
                Ingredients = IngredientsTextBox.Text,
            };

            await _hubConnection.SendAsync("CreateFood", createFoodDto);

            _hubConnection.On <bool>("CreateFoodResult", handler =>
            {
                if (handler)
                {
                    MessageBox.Show("Created.");

                    NameTextBox.Clear();
                    DescriptionTextBox.Clear();
                    IngredientsTextBox.Clear();
                }
                else
                {
                    MessageBox.Show("Faild to create.");
                }
            });
        }
Example #2
0
        /// <summary>
        /// A paraméterül kapott étel hozzáadása az aktuális felhasználó étterméhez.
        /// </summary>
        /// <param name="food">Az létrehozandó étel adatai.</param>
        /// <returns>A létrehozott étel adatai.</returns>
        public async Task <FoodDto> AddFoodToMenu(CreateFoodDto food)
        {
            string userId            = httpContext.GetCurrentUserId();
            int    ownerRestaurantId = await userRepository.GetMyRestaurantId(userId);

            return(await foodRepository.AddFoodToMenu(ownerRestaurantId, food));
        }
Example #3
0
        public async Task <ActionResult <Food> > CreateFood([FromForm] CreateFoodDto food)
        {
            if (food.Name == null)
            {
                return(NotFound());
            }

            var uniqueNameFile = "";
            var style          = NumberStyles.Number | NumberStyles.AllowCurrencySymbol;
            var provider       = new CultureInfo("ru-RU");

            if (food.Img != null)
            {
                uniqueNameFile = await RecordImg(food.Img);
            }

            try
            {
                var number = Decimal.Parse(food.Price.Replace('.', ','), style, provider);

                var foodEntity = _mapper.Map <Food>(food);
                foodEntity.Img = $"img/uploads/{uniqueNameFile}";
                _context.Foods.Add(foodEntity);

                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(BadRequest(e.Message));
            }
            return(Ok());
        }
        public async Task <FoodResponseObject> CreateOneAsync(CreateFoodDto t)
        {
            var foodGroup = await _foodGroupRepository.FindOneByIdAsync(t.FoodGroupId);

            if (foodGroup == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound, "FoodGroup not found");
            }

            var found = await _foodRepository.FindOneByNameAsync(t.Name);

            if (found != null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound, $"Food with name {t.Name} already exists");
            }

            var newFood = new Food
            {
                Name        = t.Name,
                FoodGroupId = foodGroup.Id
            };

            await _foodRepository.CreateOneAsync(newFood);

            return(FoodResponseObject.FromEntity(newFood));
        }
Example #5
0
        public async Task <IActionResult> CreateOne(
            [FromBody] CreateFoodDto createFoodDto
            )
        {
            var item = await _foodService.CreateOneAsync(createFoodDto);

            return(Ok(item));
        }
 public Food Transform(CreateFoodDto dto)
 {
     return(new Food
     {
         Name = dto.Name,
         Calorie = dto.Calorie
     });
 }
        public async Task CreateFood(CreateFoodDto createFoodDto)
        {
            DateTimeOffset now     = DateTimeOffset.Now;
            Food           newFood = new()
            {
                DateCreated  = now,
                DateModified = now,
                Description  = createFoodDto.Description,
                Ingredients  = createFoodDto.Ingredients,
                Name         = createFoodDto.Name,
            };
            await _db.Foods.AddAsync(newFood);

            int saveChangesResult = await _db.SaveChangesAsync();

            await Clients.Caller.SendAsync("CreateFoodResult", Convert.ToBoolean(saveChangesResult));
        }
Example #8
0
        /// <summary>
        /// Étel hozzáadása a megadott azonosítójú étteremhez.
        /// Ha a megadott étterem nem létezik, akkor azt kivételel jelezük.
        /// </summary>
        /// <param name="restaurantId">Az étterem azonosítója.</param>
        /// <param name="food">A hozzáadandó étel.</param>
        /// <returns>A hozzáadott étel adatai.</returns>
        public async Task <FoodDto> AddFoodToMenu(int restaurantId, CreateFoodDto food)
        {
            var dbRestaurant = (await dbContext.Restaurants
                                .SingleOrDefaultAsync(r => r.Id == restaurantId))
                               .CheckIfRestaurantNull();

            var dbFood = new Food {
                Name         = food.Name,
                Price        = food.Price,
                Description  = food.Description,
                RestaurantId = restaurantId
            };

            await dbContext.Foods.AddAsync(dbFood);

            await dbContext.SaveChangesAsync();

            return(await dbContext.Entry(dbFood).ToFoodDto());
        }
        public async Task <IActionResult> CreateFood(CreateFoodDto createFoodDto, [FromServices] IWebHostEnvironment webHostEnvironment)
        {
            if (ModelState.IsValid)
            {
                Food newFood = createFoodDto.MapToFoodEntity();
                if (createFoodDto.Photo is not null && createFoodDto.Photo.Length > 0)
                {
                    newFood.PhotoPath = await createFoodDto.Photo.UploadAsync(webHostEnvironment);
                }

                await _db.Foods.AddAsync(newFood);

                await _db.SaveChangesAsync();

                return(Json(new AxiosResponseDto {
                    Success = true, Message = "the food was successfully added", Title = "Added"
                }));
            }
            return(Json(new AxiosResponseDto {
                Success = false, Message = "please enter right values for inputs.", Title = "Error"
            }));
        }
Example #10
0
        public async Task <ActionResult <FoodDto> > AddFoodToRestaurantMenu([FromBody] CreateFoodDto food)
        {
            var createdFood = await foodManager.AddFoodToMenu(food);

            return(CreatedAtAction(nameof(GetFood), new { id = createdFood.Id }, createdFood));
        }
Example #11
0
 public IActionResult Post([FromBody] CreateFoodDto model) =>
 _mapper.Map <FoodInsertModel>(model)
 .Map(_foodCommandRepository.Insert)
 .Map(x => AllOk(new { id = x }))
 .Reduce(_ => BadRequest(), error => error is ArgumentNotSet, x => _logger.LogError(x.ToString()))
 .Reduce(_ => InternalServerError(), x => _logger.LogError(x.ToString()));
Example #12
0
 public async Task CreateFood(CreateFoodDto requestDto)
 {
     var adapter = new CreateFoodAdapter();
     await _restaurantManager.CreateFood(adapter.Transform(requestDto));
 }