public ActionResult EditAccount(ViewModels.AccountEditViewModel model) { if (!ModelState.IsValid) { return(View(model)); } using (var db = new Models.DBModel()) { var account = db.AspNetUsers.FirstOrDefault(r => r.Id == model.Id); account.Id = model.Id; account.Email = model.Email; account.EmailConfirmed = model.EmailConfirmed; account.PasswordHash = model.PasswordHash; account.SecurityStamp = model.SecurityStamp; account.PhoneNumber = model.PhoneNumber; account.PhoneNumberConfirmed = model.PhoneNumberConfirmed; account.TwoFactorEnabled = model.TwoFactorEnabled; account.LockoutEndDateUtc = model.LockoutEndDateUtc; account.LockoutEnabled = model.LockoutEnabled; account.AccessFailedCount = model.AccessFailedCount; account.UserName = model.UserName; db.SaveChanges(); } return(RedirectToAction("Admin")); }
public ActionResult Admin(string sort) { var model = new ViewModels.AccountIndexViewModel(); var db = new Models.DBModel(); model.Accounts.AddRange(db.AspNetUsers.Select(r => new ViewModels.AccountIndexViewModel.AccountListViewModel { Id = r.Id, Email = r.Email, EmailConfirmed = r.EmailConfirmed, PasswordHash = r.PasswordHash, SecurityStamp = r.SecurityStamp, PhoneNumber = r.PhoneNumber, PhoneNumberConfirmed = r.PhoneNumberConfirmed, TwoFactorEnabled = r.TwoFactorEnabled, LockoutEndDateUtc = r.LockoutEndDateUtc, LockoutEnabled = r.LockoutEnabled, AccessFailedCount = r.AccessFailedCount, UserName = r.UserName })); if (sort == "NameAsc") { model.Accounts = model.Accounts.OrderBy(r => r.UserName).ToList(); } else if (sort == "NameDesc") { model.Accounts = model.Accounts.OrderByDescending(r => r.UserName).ToList(); } model.CurrentSort = sort ?? "NameAsc"; return(View(model)); // AND THE NAME'S KIIITTENNN IZI PIZI }
public ActionResult Category(int id, string sort) { var model = new ViewModels.ProductIndexViewModel(); var db = new Models.DBModel(); model.Products.AddRange(db.Products.Where(p => p.categoryId == id).Select(r => new ViewModels.ProductIndexViewModel.ProductListViewModel { id = r.id, name = r.name, description = r.description, price = r.price })); if (sort == "NameAsc") { model.Products = model.Products.OrderBy(r => r.name).ToList(); } else if (sort == "NameDesc") { model.Products = model.Products.OrderByDescending(r => r.name).ToList(); } if (sort == "PriceAsc") { model.Products = model.Products.OrderBy(r => r.price).ToList(); } else if (sort == "PriceDesc") { model.Products = model.Products.OrderByDescending(r => r.price).ToList(); } model.CurrentSort = sort ?? "NameAsc"; return(View(model)); }
// GET: Employee/GetData public ActionResult GetData() { using (Models.DBModel db = new Models.DBModel()) { List<Employee> emp = db.Employees.ToList<Employee>(); return Json(new { data = emp },JsonRequestBehavior.AllowGet); } }
public ActionResult EditCategory(int id) { using (var db = new Models.DBModel()) { var category = db.ProductCategories.FirstOrDefault(p => p.id == id); var model = new ViewModels.CategoryEditViewModel { name = category.name, id = category.id }; return(View(model)); } }
public ActionResult Product(int id) { using (var db = new Models.DBModel()) { var product = db.Products.FirstOrDefault(r => r.id == id); var model = new ViewModels.ProductViewViewModel { name = product.name, description = product.description, price = product.price }; return(View(model)); } }
public ActionResult EditCategory(ViewModels.CategoryEditViewModel model) { if (!ModelState.IsValid) { return(View(model)); } using (var db = new Models.DBModel()) { var category = db.ProductCategories.FirstOrDefault(r => r.id == model.id); category.name = model.name; category.id = model.id; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Edit(int id) { using (var db = new Models.DBModel()) { var product = db.Products.FirstOrDefault(p => p.id == id); var model = new ViewModels.ProductEditViewModel { name = product.name, description = product.description, price = product.price, id = product.id, categoryId = product.categoryId }; return(View(model)); } }
public ActionResult Edit(ViewModels.ProductEditViewModel model) { if (!ModelState.IsValid) { return(View(model)); } using (var db = new Models.DBModel()) { var product = db.Products.FirstOrDefault(r => r.id == model.id); product.name = model.name; product.description = model.description; product.price = model.price; product.id = model.id; product.categoryId = model.categoryId; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult CreateCategory(ViewModels.CategoryCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } using (var db = new Models.DBModel()) { var category = new Models.ProductCategory { id = model.id, name = model.name }; db.ProductCategories.Add(category); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult CreateProduct(ViewModels.ProductCreateViewModel model) { if (!ModelState.IsValid) { return(View(model)); } using (var db = new Models.DBModel()) { var product = new Models.Product { id = model.id, name = model.name, description = model.description, price = model.price, categoryId = model.categoryId }; db.Products.Add(product); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult EditAccount(string id) { using (var db = new Models.DBModel()) { var account = db.AspNetUsers.FirstOrDefault(r => r.Id == id); var model = new ViewModels.AccountEditViewModel { Id = account.Id, Email = account.Email, EmailConfirmed = account.EmailConfirmed, PasswordHash = account.PasswordHash, SecurityStamp = account.SecurityStamp, PhoneNumber = account.PhoneNumber, PhoneNumberConfirmed = account.PhoneNumberConfirmed, TwoFactorEnabled = account.TwoFactorEnabled, LockoutEndDateUtc = account.LockoutEndDateUtc, LockoutEnabled = account.LockoutEnabled, AccessFailedCount = account.AccessFailedCount, UserName = account.UserName }; return(View(model)); } }
public ActionResult Search(string query, string sort) { var model = new ViewModels.ProductIndexViewModel(); var db = new Models.DBModel(); model.Products.AddRange(db.Products.Where(p => p.name.Contains(query) || p.description.Contains(query)).Select(r => new ViewModels.ProductIndexViewModel.ProductListViewModel { id = r.id, name = r.name, description = r.description, price = r.price })); model.CurrentQuery = query; if (sort == "NameAsc") { model.Products = model.Products.OrderBy(r => r.name).ToList(); } else if (sort == "NameDesc") { model.Products = model.Products.OrderByDescending(r => r.name).ToList(); } if (sort == "PriceAsc") { model.Products = model.Products.OrderBy(r => r.price).ToList(); } else if (sort == "PriceDesc") { model.Products = model.Products.OrderByDescending(r => r.price).ToList(); } model.CurrentSort = sort ?? "NameAsc"; return(View(model)); }
// GET: Category public ActionResult Index(string sort) { var model = new ViewModels.CategoryIndexViewModel(); var db = new Models.DBModel(); model.Categories.AddRange(db.ProductCategories.Select(r => new ViewModels.CategoryIndexViewModel.CategoryListViewModel { id = r.id, name = r.name })); if (sort == "NameAsc") { model.Categories = model.Categories.OrderBy(r => r.name).ToList(); } else if (sort == "NameDesc") { model.Categories = model.Categories.OrderByDescending(r => r.name).ToList(); } model.CurrentSort = sort ?? "NameAsc"; return(View(model)); }