public ActionResult Create(TechnicalSpecsViewModel technicalSpecsViewModel) { try { technicalSpecsViewModel.TechnicalSpec.UpdatedDate = DateTime.UtcNow; technicalSpecsViewModel.TechnicalSpec.UpdatedBy = User.Identity.GetUserId(); // TODO: Add insert logic here if (technicalSpecsViewModel.TechnicalSpec.TechnicalSpecId > 0) { technicalSpecsService.UpdateTechnicalSpecs(technicalSpecsViewModel.TechnicalSpec.MapClientToServer()); } else { technicalSpecsViewModel.TechnicalSpec.CreatedDate = DateTime.UtcNow; technicalSpecsViewModel.TechnicalSpec.CreatedBy = User.Identity.GetUserId(); technicalSpecsService.AddTechnicalSpecs(technicalSpecsViewModel.TechnicalSpec.MapClientToServer()); } TempData["message"] = new MessageViewModel { IsSaved = true, Message = "Your data has been saved successfully!" }; return(RedirectToAction("Create")); } catch (Exception ex) { return(View()); } }
public ActionResult Create(int?id) { TechnicalSpecsViewModel technicalSpecsView = new TechnicalSpecsViewModel(); TMD.Models.DomainModels.TechnicalSpec techSpec = null; if (id != null) { techSpec = technicalSpecsService.GetPTechnicalSpecsById(Convert.ToInt32(id)); } if (techSpec != null) { technicalSpecsView.TechnicalSpec = techSpec.MapServerToClient(); } else { technicalSpecsView.TechnicalSpec = new Models.TechnicalSpecsModel(); } technicalSpecsView.TechnicalSpecs = technicalSpecsService.GetAllTechnicalSpecs().Select(x => x.MapServerToClient()).ToList(); ViewBag.MessageVM = TempData["message"] as MessageViewModel; return(View(technicalSpecsView)); }