public ActionResult Create(RfpProduct model) { ViewData["Types"] = _productTypeFacade.GetAll(); //ViewData["Orgs"] = _organizationFacade.GetAll(); var resp_contact = model.RACIContactList.FirstOrDefault(p => p.lk5_key.ToString() == "5592b25d-d98a-4914-9c8e-ac28d6c11116"); if (resp_contact == null) { ModelState.AddModelError("", "Please add team member with 'Responsible' role."); } try { if (ModelState.IsValid) { model.prd_add_date = DateTime.Now; model.prd_org_key = CurrentUser.User.org_key; var response = _productFacade.Add(model, CurrentUser.User.ct_key.ToString()); if (response.Success) { // Save added contacts to RACI. foreach (var contact in model.RACIContactList) { _contactFacade.Add_RACI_Contact(contact.lk5_key.ToString(), contact.ct_key.ToString(), null, model.prd_key.ToString(), CurrentUser.User.ct_key.ToString()); } } } else { return(View(model)); } return(RedirectToAction("", "Product")); } catch { return(View(model)); } }
public ActionResult Create(CreateProductViewModel model) { if (ModelState.IsValid) { var supplier = _productFacade.GetSuppliers().FirstOrDefault(s => s.Id == model.SupplierId); if (supplier == null) { supplier = new Supplier { Id = Guid.NewGuid(), Name = model.SupplierName }; } var product = _productFactory.Create((ProductType)model.ProductTypeId, Guid.NewGuid(), model.Name, model.Provision, model.StartPrice, supplier); switch ((ProductType)model.ProductTypeId) { case ProductType.Antique: (product as AntiqueProduct).TimeEpoch = (TimeEpoch)model.TimeEpochId; break; case ProductType.Mass: case ProductType.Modern: var designer = _productFacade.GetDesigners().FirstOrDefault(d => d.Id == model.DesignerId); if (designer == null) { designer = new Designer { Id = Guid.NewGuid(), Name = model.DesignerName }; } (product as DesignerProduct).Designer = designer; break; default: break; } _productFacade.Add(product); } return(RedirectToAction("Index")); }