public ActionResult Add(int id, AddUserLicenseViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var parsedBuyDate = DateTime.ParseExact(model.BuyDate, "d", CultureInfo.CreateSpecificCulture("de-DE")); var expiryDate = parsedBuyDate.AddYears(model.LicenseYears); var customerModules = new Customer_Modules(); customerModules.BuyDate = parsedBuyDate; customerModules.ExpiryDate = expiryDate; customerModules.ModId = model.ModId; _db.Users.Single(u => u.UId == id).Customer_Modules.Add(customerModules); _db.SaveChanges(); TempData["uihint"] = new UiHint("Erfolg!", "Die Lizenz wurde hinzugefügt!", new { @class = "alert alert-success" }); return(RedirectToAction("Details", "User", new { id = id })); } catch { return(View(model)); } }
public ActionResult Add(int id) { var viewModel = new AddUserLicenseViewModel { User = _db.Users.Single(u => u.UId == id) }; if (viewModel.PopulateSelectList()) { return(View(viewModel)); } TempData["uihint"] = new UiHint("Das geht nicht.", "Der Benutzer verfügt schon über die Lizenzen aller Module!", new { @class = "alert alert-error" }); return(RedirectToAction("Details", "User", new { id = id })); }