public ActionResult Create() { var viewmodel = new FundAddViewModel(); viewmodel.AvailableDbSources = new List <SelectListItem>() { new SelectListItem() { Text = DbSource.GC.ToString(), Value = ((int)DbSource.GC).ToString() }, new SelectListItem() { Text = DbSource.DIST.ToString(), Value = ((int)DbSource.DIST).ToString() } }; return(View(viewmodel)); }
public ActionResult Create(FundAddViewModel viewmodel) { if (ModelState.IsValid) { if (_gpDynamicsService.GetAllFunds().FirstOrDefault(t => t.Number.Trim() == viewmodel.FundNumber) == null) { Danger($"This fund number <strong>{viewmodel.FundNumber}</strong>, does not exist in GP Databse"); } else if (_fundService.GetByFundNumberAndYear(viewmodel.FundNumber, viewmodel.Year.Value) != null) { Danger($"A Fund with same Number <strong>{viewmodel.FundNumber}</strong> already exists within the same year <strong>{viewmodel.Year.Value}</strong>."); } else { var entity = Mapper.Map <FundAddViewModel, Fund>(viewmodel); _fundService.Add(new List <Fund>() { entity }); Success($"<strong>{entity.DisplayName} - {entity.FundNumber}</strong> was successfully saved."); return(RedirectToAction("Index", new { year = entity.Year, dbsource = entity.DbSource })); } } viewmodel.AvailableDbSources = new List <SelectListItem>() { new SelectListItem() { Text = DbSource.GC.ToString(), Value = ((int)DbSource.GC).ToString() }, new SelectListItem() { Text = DbSource.DIST.ToString(), Value = ((int)DbSource.DIST).ToString() } }; return(View(viewmodel)); }