//[ValidateAntiForgeryToken] public ActionResult Create(TimesheetFormViewModel viewModel) { if (!ModelState.IsValid) { return(View("Create", viewModel)); } var timesheet = new Timesheet { ArtistId = User.Identity.GetUserId(), StartDay = viewModel.StartTime, //EndDay = viewModel.EndTime }; _context.Timesheets.Add(timesheet); _context.SaveChanges(); return(RedirectToAction("ListView", "Timesheet")); }
public ActionResult Create(TimesheetFormViewModel viewModel) { if (!ModelState.IsValid) { return(View("Create", viewModel)); } var timesheet = new Timesheet { Name = User.Identity.Name, IP = viewModel.IP, UserId = User.Identity.GetUserId(), StartDay = viewModel.GetDateTimeStart(), EndDay = viewModel.GetDateTimeEnd() }; _context.Timesheets.Add(timesheet); _context.SaveChanges(); return(RedirectToAction("Index", "Timesheet")); }
public ActionResult EditView([Bind(Include = /*"Id,StartDay,EndDay,UserId,Name"*/ "Id,Name,IP,StartDay,EndDay,GetDifferenceTimes()")] TimesheetFormViewModel viewModel) { var timesheet = new Timesheet { //UserId = User.Identity.GetUserId(), Name = User.Identity.Name, IP = viewModel.IP, UserId = User.Identity.GetUserId(), StartDay = viewModel.GetDateTimeStart(), EndDay = viewModel.GetDateTimeEnd() }; if (ModelState.IsValid) { _context.Entry(timesheet).State = EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("Index")); } return(View(timesheet)); }
public ActionResult EditView(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Timesheet timesheet = _context.Timesheets.Find(id); if (timesheet == null) { return(HttpNotFound()); } TimesheetFormViewModel viewModel = new TimesheetFormViewModel { Date = string.Format("{0} {1} {2}", timesheet.StartDay.Day, timesheet.StartDay.Month, timesheet.StartDay.Year), Id = timesheet.Id, IP = timesheet.IP, TimeStart = string.Format("{0}:{1}", timesheet.StartDay.Hour, timesheet.StartDay.Minute) }; ViewBag.StartDay = viewModel.TimeStart; return(View(viewModel)); }
public ActionResult Create() { var viewModel = new TimesheetFormViewModel(); return(View(viewModel)); }