Exemple #1
0
 public ActionResult Create(Dish dish)
 {
     if (!ModelState.IsValid)
     {
         return(View(dish));
     }
     dishService.CreateDish(dish);
     return(RedirectToAction("Index"));
 }
Exemple #2
0
 public ActionResult <Dish> Post([FromBody] Dish dish, int restaurantId)
 {
     try
     {
         return(Ok(dishService.CreateDish(restaurantId, dish)));
     }
     catch
     {
         throw new Exception("Not possible to show");
     }
 }
        public void CreateDish()
        {
            var dish = new Dish
            {
                DishName  = this.DishName,
                DishesFor = this.DishesFor,
                Created   = DateTime.Now,
                MealId    = this.MealId
            };

            _dishService.CreateDish(dish);
        }
 public IActionResult Create([Bind("Id,Name,Description,Image,Type,Restriction,Size,Price")] Dish dish, IFormFile image)
 {
     if (ModelState.IsValid)
     {
         if (image != null)
         {
             if (image.Length > 0)
             //Convert Image to byte and save to database
             {
                 using (var stream = new MemoryStream())
                 {
                     image.CopyTo(stream);
                     dish.Image = stream.ToArray();
                 }
             }
         }
         _service.CreateDish(dish);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(dish));
 }
        public async Task <HttpResponseMessage> PostFormData()
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            string root     = HttpContext.Current.Server.MapPath("~/Images/Dish");
            var    provider = new CustomMultipartFormDataStreamProvider(root); //new MultipartFormDataStreamProvider(root);

            try
            {
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);

                var pathArray =
                    provider.FileData.Select(file => file.LocalFileName.Substring(root.Length + 1)).ToArray();

                var detailsDish = new DishModelDetailsInfo
                {
                    Description = provider.FormData.Get("Description"),
                    Energy      = Convert.ToInt32(provider.FormData.Get("Energy")),
                    ImagePath   = pathArray,
                    Ingridients = provider.FormData.Get("Ingridients"),
                    Name        = provider.FormData.Get("Name"),
                    Price       = Convert.ToInt32(provider.FormData.Get("Price")),
                    Weight      = Convert.ToInt32(provider.FormData.Get("Weight"))
                };

                _dishService.CreateDish(detailsDish);

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }
Exemple #6
0
        public ActionResult Post([FromRoute] int restaurantId, [FromBody] CreateDishDto dto)
        {
            var newDishId = _dishService.CreateDish(restaurantId, dto);

            return(Created($"api/restaurant/{restaurantId}/dish/{newDishId}", null));
        }
Exemple #7
0
        public async Task <ActionResult> CreateDish([FromRoute] int restaurantId, [FromBody] CreateDishDTO dto)
        {
            var newDishId = await _service.CreateDish(restaurantId, dto);

            return(Created($"api/restaurant/{restaurantId}/dish/{newDishId}", null));
        }
Exemple #8
0
        public ActionResult Create([FromRoute] int restaurantId, [FromBody] CreateDishRequest request)
        {
            int id = _dishService.CreateDish(restaurantId, request);

            return(Created($"api/v1/restaurant/{restaurantId}/dish/{id}", null));
        }