Пример #1
0
        public ActionResult Create(CourtsViewModel courtsViewModel)
        {
            if (ModelState.IsValid)
            {
                var maxId = db.Courts.Max(m => m.CourtId) + 1;
                var userId = User.Identity.GetUserId();
                var court = new Court()
                {
                    CourtId = maxId,
                    CourtCode = "C-" + maxId,
                    CourtName = courtsViewModel.CourtName,
                    CourtRemarks = courtsViewModel.CourtRemarks,
                    CourtStatus = courtsViewModel.CourtStatus,
                    CourtDateTimeStamp = DateTime.Now,
                    UserId = userId,
                    TerminalName = Environment.MachineName
                };

                db.Courts.Add(court);
                db.SaveChanges();
                TempData["Message"] = "Record Successfully Entered";
                return RedirectToAction("Index");
            }
            else
            {
                return View(courtsViewModel);
            }
        }
Пример #2
0
 public ActionResult Delete(int id)
 {
     var court = db.Courts.Find(id);
     if (court == null)
     {
         return HttpNotFound();
     }
     CourtsViewModel courtViewModel = new CourtsViewModel()
     {
         CourtId = id,
         CourtName = court.CourtName,
         CourtRemarks = court.CourtRemarks,
         CourtStatus = court.CourtStatus
     };
     return View(courtViewModel);
 }
Пример #3
0
 public ActionResult Edit(CourtsViewModel courtsViewModel)
 {
     var court = db.Courts.Find(courtsViewModel.CourtId);
     if (ModelState.IsValid)
     {
         court.CourtName = courtsViewModel.CourtName;
         court.CourtRemarks = courtsViewModel.CourtRemarks;
         court.CourtStatus = courtsViewModel.CourtStatus;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(courtsViewModel);
 }