示例#1
0
        public async Task <ActionResult> Index(string sortOrder, int?page)
        {
            ViewData["CurrentSort"]       = sortOrder;
            ViewData["VINSortParm"]       = String.IsNullOrEmpty(sortOrder) ? "vin_desc" : "";
            ViewData["CustFNameSortParm"] = sortOrder == "custfname" ? "custfname_desc" : "custfname";
            var titles = from t in _db.Titles.Where(t => t.IsDeleted == false)
                         select t;

            switch (sortOrder)
            {
            case "Vin_desc":
                titles = titles.OrderByDescending(r => r.Id);
                break;

            case "custfname":
                titles = titles.OrderBy(r => r.CustFName);
                break;

            case "custfname_desc":
                titles = titles.OrderByDescending(r => r.CustFName);
                break;

            default:
                titles = titles.OrderBy(r => r.Id);
                break;
            }
            const int pageSize       = 20;
            var       titleviewmodel = new TitleViewModel(0, _db, _userManager)
            {
                PaginatedTitles = await PaginatedList <Title> .CreateAsync(titles.AsNoTracking(), page ?? 1, pageSize)
            };

            ViewData["Pages"] = titleviewmodel.PaginatedTitles.TotalPages;
            return(View(titleviewmodel));
        }
示例#2
0
 public void DeleteTitleAndSave(TitleViewModel vm, ApplicationDbContext db, string userid)
 {
     vm.Title.IsDeleted       = true;
     vm.Title.DeletedDt       = DateTime.Now;
     vm.Title.DeletedBy       = userid;
     db.Entry(vm.Title).State = EntityState.Modified;
     db.SaveChanges();
 }
示例#3
0
 public ActionResult DeleteConfirmed(TitleViewModel vm)
 {
     if (!ModelState.IsValid)
     {
         return(new StatusCodeResult(400));
     }
     vm.DeleteTitleAndSave(vm, _db, _userManager.GetUserAsync(User).Result.Id.ToString());
     return(RedirectToAction("Index", "OosTitlesDashboard"));
 }
示例#4
0
 public ActionResult Edit(TitleViewModel vm)
 {
     if (!ModelState.IsValid)
     {
         return(View(vm));
     }
     vm.UpdateTitleAndSave(vm, _db);
     return(RedirectToAction("Index", "OosTitlesDashboard"));
 }
示例#5
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new StatusCodeResult(400));
            }
            var vm = new TitleViewModel(id, _db, _userManager);

            if (vm.Title == null)
            {
                return(NotFound());
            }
            return(View(vm));
        }
示例#6
0
 public void UpdateTitleAndSave(TitleViewModel vm, ApplicationDbContext db)
 {
     db.Entry(vm.Title).State = EntityState.Modified;
     db.SaveChanges();
 }