public ActionResult Create(IFormCollection collection) { int userID = (int)TempData["UserID"]; int locationID = int.Parse(collection["LocationID"]); Location location = new Location(s_libHelper.Locations.First(l => l.ID == locationID)); LibI.IUser lU = s_libHelper.Users.First(u => u.AccountID == userID); User user = new User(lU, new Location(lU.DefaultLocation)); Order order = new Order(location.Lib.SuggestOrder(lU), location, user); s_libHelper.Reload(); var orderIDs = new List <int>(TempData["OrderIDs"] as int[] ?? new int[] { }) { order.ID }; TempData["OrderIDs"] = orderIDs.ToArray <int>(); return(RedirectToAction(nameof(Index), new { id = userID })); }
public ActionResult Create(Location location) { try { if (!ModelState.IsValid) { throw new ArgumentException("invalid location."); } location.Commit(); s_libHelper.Reload(); return(RedirectToAction(nameof(Index))); } catch { return(RedirectToAction(nameof(Create))); } }
public ActionResult Create(User user) { try { if (!ModelState.IsValid) { throw new ArgumentException("invalid user."); } user.DefaultLocation = new Location(s_libHelper.Locations.First(l => l.ID == user.DefaultLocationID)); user.Commit(); s_libHelper.Reload(); return(RedirectToAction(nameof(Index))); } catch { return(RedirectToAction(nameof(Create))); } }