public ActionResult PostAlertConfirmed(int id) { Restaurant rest = db.Restaurants.Find(id); var redItems = rest.RestaurantItems.Where(x => x.StockCode == 3); if (redItems.Any()) { var alert = new Alert { TimeCreated = DateTime.Now }; var alertItems = new List <ItemAlert>(); foreach (var item in redItems) { alertItems.Add(new ItemAlert { RestaurantItemId = item.Id, StockCode = item.StockCode }); } alert.ItemAlerts = alertItems; db.Alerts.Add(alert); db.SaveChanges(); SelectEmployees(rest, alert); } return(RedirectToAction("Index", new { id })); }
public ActionResult Create(RestaurantVM rvm) { if (ModelState.IsValid) { var userId = User.Identity.GetUserId(); Restaurant restaurant = new Restaurant(rvm); if (rvm.CreateGroup) { restaurant.RestaurantGroup = new RestaurantGroup { Name = rvm.GroupName, OwnerId = userId }; } else { restaurant.GroupId = rvm.GroupId; } db.Restaurants.Add(restaurant); db.SaveChanges(); return(RedirectToAction("Index")); } var ownerID = User.Identity.GetUserId(); ViewBag.GroupId = new SelectList(db.RestaurantGroups.Where(x => x.OwnerId == ownerID), "Id", "Name", rvm.GroupId); return(View(rvm)); }
public ActionResult ChangeStock(int?id, int?code) { var restItem = db.RestaurantItems.Find(id); if (id != null && code != null) { restItem.StockCode = code.Value; db.Entry(restItem).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index", new { id = restItem.RestaurantId })); }
public ActionResult Create(Person person) { if (ModelState.IsValid) { db.People.Add(person); db.SaveChanges(); return(RedirectToAction("Index", new { id = person.RestaurantId })); } //ViewBag.RestaurantId = new SelectList(db.Restaurants, "Id", "Address", person.RestaurantId); return(View(person)); }
private async Task <ApplicationUser> CreateUser(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { UserManager.AddToRole(user.Id, model.isOwner ? "owner" : "manager"); var userProfile = new UserProfile(model, user.Id); using (CapstoneDBEntities db = new CapstoneDBEntities()) { db.UserProfiles.Add(userProfile); db.SaveChanges(); } // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(user); } AddErrors(result); } return(null); }
public ActionResult EditSchedule(EmployeeScheduleVM scheduleVM, int?id) { if (ModelState.IsValid) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Person employee = db.People.Find(id); if (employee == null) { return(HttpNotFound()); } employee.UpdateSchedule(scheduleVM, db); db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", new { id = employee.RestaurantId })); } return(View(scheduleVM)); }