public ActionResult Create([Bind(Include = "ID,HoursAvailable,Date,UserID")] Day day, int recurrence) { if (ModelState.IsValid) { db.Days.Add(day); db.SaveChanges(); //Keep those rascals under control! if (recurrence > 24) { recurrence = 24; } var day_to_use = day.Date; while (recurrence > 0) { var re_day = new Day(); day_to_use = day_to_use.AddDays(7); re_day.Date = day_to_use; re_day.HoursAvailable = day.HoursAvailable; re_day.UserID = day.UserID; db.Days.Add(re_day); db.SaveChanges(); recurrence--; } return(RedirectToAction("Index")); } ViewBag.UserID = new SelectList(db.Users, "ID", "FirstName", day.UserID); return(View(day)); }
public ActionResult Create([Bind(Include = "ID,FirstName,LastName,Email,Password")] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Create([Bind(Include = "ID,Description,UserID")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserID = new SelectList(db.Users, "ID", "FirstName", category.UserID); return(View(category)); }
public ActionResult Create([Bind(Include = "ID,Title,OccursAt,Duration,Priority,CompleteBy,IsComplete,Location,UserID,CategoryID")] Event @event, int recurrence) { if (ModelState.IsValid) { db.Events.Add(@event); db.SaveChanges(); if (recurrence > 24) { recurrence = 24; } var Occurs = @event.OccursAt; var Complete = @event.CompleteBy; while (recurrence > 0) { var re_event = new Event(); Occurs = Occurs.AddDays(7); Complete = Complete.AddDays(7); re_event.OccursAt = Occurs; re_event.CompleteBy = Complete; re_event.IsComplete = @event.IsComplete; re_event.Priority = @event.Priority; re_event.Title = @event.Title; re_event.UserID = @event.UserID; re_event.CategoryID = @event.CategoryID; re_event.Location = @event.Location; re_event.AutoAssign = @event.AutoAssign; re_event.Duration = @event.Duration; db.Events.Add(re_event); db.SaveChanges(); recurrence--; } return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Categories, "ID", "Description", @event.CategoryID); ViewBag.UserID = new SelectList(db.Users, "ID", "FirstName", @event.UserID); return(View(@event)); }
public ActionResult Register(User U) { try { if (ModelState.IsValid) { using (calendarEntities db = new calendarEntities()) { db.Users.Add(U); db.SaveChanges(); ModelState.Clear(); U = null; ViewBag.Message = "Registration Successfull"; } } else { ModelState.AddModelError("", "Inocrrect Data"); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"" + "{1}\" " + "has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } return(View()); }