//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")); } }
public void HideLoading() { if (BoxModel != null) { if (typeof(LoadingBoxViewModel) == BoxModel.GetType()) { ((LoadingBoxViewModel)BoxModel).IsShow = false; } } }
//Edit box with a specified BoxModel public ActionResult Edit(BoxModel viewModel) { if (ModelState.IsValid) { BoxModel old = _models.Where(model => model.ID == viewModel.ID).FirstOrDefault(); foreach (PropertyInfo property in old.GetType().GetProperties()) { property.SetValue(old, property.GetValue(viewModel)); } return(RedirectToAction("List")); } else { return(RedirectToAction("Edit", new { id = viewModel.ID })); } }
//Edit box with a specified BoxModel public ActionResult Edit(BoxModel viewModel) { if (ModelState.IsValid) { BoxDTO @new = new BoxDTO(); foreach (PropertyInfo property in @new.GetType().GetProperties()) { property.SetValue(@new, viewModel.GetType().GetProperty(property.Name).GetValue(viewModel)); } _service.Edit(@new); return(RedirectToAction("List")); } else { return(RedirectToAction("Edit", new { id = viewModel.ID })); } }