示例#1
0
 public Food(AddFoodModel model)
 {
     this.Description     = model.Description;
     this.Discount        = model.Discount;
     this.FoodType        = model.FoodType;
     this.Name            = model.Name;
     this.PaymentOption   = model.PaymentOption;
     this.PreparationTime = model.PreparationTime;
     this.Price           = model.Price;
 }
示例#2
0
        public IActionResult Post([FromBody] AddFoodModel model)
        {
            Food food = new Food(model);

            _foodrepo.Add(food);
            if (_foodrepo.SaveChanges() == 0)
            {
                throw new ApplicationException("failed to create food");
            }
            var foodDto = _foodMapper.MapFoodDto(food);

            return(Ok(foodDto));
        }
示例#3
0
        public IActionResult addFood([FromBody] AddFoodModel foodDto)
        {
            foodDto.name = foodDto.name.ToLower();

            try
            {
                // save
                var food = new Food()
                {
                    name       = foodDto.name,
                    price      = foodDto.price,
                    SellerId   = foodDto.SellerId,
                    CategoryId = foodDto.CategoryId
                };
                _foodService.Add(food);
                return(Ok());
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }