public ActionResult Create(QuoteFormModel quotemodel) { try { Quote quote = AutoMapper.Mapper.Map<QuoteFormModel, Quote>(quotemodel); quote.Carrier = ((CarrierEnum)quotemodel.Carrier).ToString(); quote.QuoteStage = ((QuoteStageEnum)quotemodel.QuoteStage).ToString(); if (ModelState.IsValid) { if (quote.ID == 0) { quoteService.CreateQuote(quote); } else { quoteService.EditQuote(quote); } ViewBag.successMessage = "Quote Saved Successfully"; ViewBag.errorMessage = ""; } else { string validationErrors = string.Join(",", ModelState.Values.Where(E => E.Errors.Count > 0) .SelectMany(E => E.Errors).Select(E => E.ErrorMessage).ToArray()); ViewBag.successMessage = ""; ViewBag.errorMessage = validationErrors; } quotemodel = getDropDownValues(quotemodel); } catch (Exception ex) { ViewBag.successMessage = ""; ViewBag.errorMessage = string.Format("Error in Quote Save : {0}", ex.Message); quotemodel = getDropDownValues(quotemodel); } return View("QuoteCreate", quotemodel); }
public ActionResult Create(long Id = 0) { ViewBag.SuccessMessage = ""; QuoteFormModel quoteFormModel = new QuoteFormModel(); if (Id != 0) { Quote quote = quoteService.GetQuote(Id); quoteFormModel = AutoMapper.Mapper.Map<Quote, QuoteFormModel>(quote); if(!string.IsNullOrEmpty(quote.QuoteStage)) quoteFormModel.QuoteStage = (int)Enum.Parse(typeof(QuoteStageEnum), quote.QuoteStage); if(!string.IsNullOrEmpty(quote.Carrier)) quoteFormModel.Carrier = (int)Enum.Parse(typeof(CarrierEnum), quote.Carrier); } quoteFormModel = getDropDownValues(quoteFormModel); return View("QuoteCreate", quoteFormModel); }
private QuoteFormModel getDropDownValues(QuoteFormModel quoteFormModel) { if (quoteFormModel.AssignedToUserGroup == UserGroup.group) { var groups = groupService.GetGroups(); List<SelectListItem> grpItems = new List<SelectListItem>(); grpItems.AddRange(groups.OrderBy(grp => grp.Name) .Select(grp => new SelectListItem { Selected = (grp.ID == quoteFormModel.AssignedTo), Text = grp.Name, Value = grp.ID.ToString() })); quoteFormModel.GrpUserList = grpItems; } else { quoteFormModel.AssignedToUserGroup = UserGroup.user; var users = userService.GetUsers(); List<SelectListItem> items = new List<SelectListItem>(); items.AddRange(users.OrderBy(user => user.Name) .Select(user => new SelectListItem { Selected = (user.ID == quoteFormModel.AssignedTo), Text = user.Name, Value = user.ID.ToString() })); quoteFormModel.GrpUserList = items; } var managers = userService.GetUsers(); List<SelectListItem> managersitems = new List<SelectListItem>(); managersitems.AddRange(managers.OrderBy(user => user.Name) .Select(user => new SelectListItem { Selected = (user.ID == quoteFormModel.InventoryManager), Text = user.Name, Value = user.ID.ToString() })); quoteFormModel.UserList = managersitems; IEnumerable<QuoteStageEnum> QuoteStages = Enum.GetValues(typeof(QuoteStageEnum)) .Cast<QuoteStageEnum>(); quoteFormModel.QuoteStageList = from src in QuoteStages select new SelectListItem { Text = src.ToString(), Value = ((int)src).ToString() }; IEnumerable<CarrierEnum> Carriers = Enum.GetValues(typeof(CarrierEnum)) .Cast<CarrierEnum>(); quoteFormModel.CarrierList = from src in Carriers select new SelectListItem { Text = src.ToString(), Value = ((int)src).ToString() }; var accounts = accountService.GetAccounts(); List<SelectListItem> accountsitems = new List<SelectListItem>(); accountsitems.AddRange(accounts.OrderBy(account => account.AccountName) .Select(account => new SelectListItem { Selected = (account.ID == quoteFormModel.Account), Text = account.AccountName, Value = account.ID.ToString() })); quoteFormModel.AccountList = accountsitems; var potentials = potentialService.GetPotentials(); List<SelectListItem> potentialItems = new List<SelectListItem>(); potentialItems.AddRange(potentials.OrderBy(x => x.PotentialName) .Select(x => new SelectListItem { Selected = (x.ID == quoteFormModel.Potential), Text = x.PotentialName, Value = x.ID.ToString() })); quoteFormModel.PotentialList = potentialItems; var contacts = contactService.GetContacts(); List<SelectListItem> contactItems = new List<SelectListItem>(); contactItems.AddRange(contacts.OrderBy(x => x.FirstName) .Select(x => new SelectListItem { Selected = (x.ID == quoteFormModel.Contact), Text = x.FirstName, Value = x.ID.ToString() } )); quoteFormModel.ContactList = contactItems; return quoteFormModel; }
public ActionResult Details(long Id) { QuoteFormModel quoteDetails = new QuoteFormModel(); Quote quote = quoteService.GetQuote(Id); quoteDetails = AutoMapper.Mapper.Map<Quote, QuoteFormModel>(quote); if (quoteDetails.AssignedToUserGroup == UserGroup.group) { quoteDetails.AssignedToName = groupService.GetGroup(quoteDetails.AssignedTo) != null ? groupService.GetGroup(quoteDetails.AssignedTo).Name : string.Empty; } else { quoteDetails.AssignedToName = userService.GetUser(quoteDetails.AssignedTo) != null ? userService.GetUser(quoteDetails.AssignedTo).Name : string.Empty; } quoteDetails.QuoteStageName = quote.QuoteStage; quoteDetails.CarrierName = quote.Carrier; quoteDetails.AccountName = accountService.GetAccount(quoteDetails.Account) != null ? accountService.GetAccount(quoteDetails.Account).AccountName : string.Empty; if (quoteDetails.Contact != null) quoteDetails.ContactName = contactService.GetContact(long.Parse(quoteDetails.Contact.ToString())) != null ? contactService.GetContact(long.Parse(quoteDetails.Contact.ToString())).FirstName : string.Empty; if(quoteDetails.Potential != null) quoteDetails.PotentialName = potentialService.GetPotential(long.Parse(quoteDetails.Potential.ToString())) != null ? potentialService.GetPotential(long.Parse(quoteDetails.Potential.ToString())).PotentialName : string.Empty; if(quoteDetails.InventoryManager != null) quoteDetails.InventoryManagerName = userService.GetUser(long.Parse(quoteDetails.InventoryManager.ToString())) != null ? userService.GetUser(long.Parse(quoteDetails.InventoryManager.ToString())).Name : string.Empty; return View("QuoteDetails", quoteDetails); }