Пример #1
0
        //Output information of created box
        public ActionResult RequestBox(BoxModel viewModel)
        {
            //Show a view consisting of the fields of the box
            if (ModelState.IsValid)
            {
                string message = string.Format("The request for box with with size {0}:{1}:{2} and weight {3}, color {4} and material {5} was successfully accepted."
                                               , viewModel.Width, viewModel.Height, viewModel.Length, viewModel.Weight, viewModel.Colour, viewModel.Material);

                //Create DTO
                BoxDTO box = new BoxDTO();
                //Set Properties of DTO
                foreach (PropertyInfo property in box.GetType().GetProperties())
                {
                    property.SetValue(box, viewModel.GetType().GetProperty(property.Name).GetValue(viewModel));
                }
                _service.Insert(box);

                ViewBag.SuccessMessage = message;
                return(View());
            }
            //Go back to creating a box, because something was not valid
            else
            {
                TempData["viewModel"] = viewModel;
                return(RedirectToAction("Create"));
            }
        }
Пример #2
0
 public IHttpActionResult PostBox(Box obj)
 {
     return(Ok(boxService.Insert(obj)));
 }