private void updateProductList(int id, int sizeId, string func, int sizeAlter = 0, string sortOrder = "#") { IEnumerable <Product> products = this.db.Product; // products = products.Where(s => s.name.Contains(search) || s.supplier.Contains(search)); // IEnumerable <ProductSize> sizes = this.db.ProductSize; sizes = sizes.Where(s => s.product == this.aProducts.choosenProduct.id); for (int i = 0; i < pSortParams.Length; i++) { if (pSortParams[i].Contains(sortOrder)) { pSortParams[i] = sortOrder + (pSortParams[i].Contains("_asc") ? "_desc" : "_asc"); switch (pSortParams[i]) { case "cat_desc": products = products.OrderByDescending(p => p.category); break; case "cat_asc": products = products.OrderBy(p => p.category); break; case "sup_desc": products = products.OrderByDescending(p => p.supplier); break; case "sup_asc": products = products.OrderBy(p => p.supplier); break; case "price_desc": products = products.OrderByDescending(p => p.price); break; case "price_asc": products = products.OrderBy(p => p.price); break; case "name_desc": products = products.OrderByDescending(p => p.name); break; case "name_asc": products = products.OrderBy(p => p.name); break; case "size_desc": sizes = sizes.OrderByDescending(p => p.size); break; case "size_asc": sizes = sizes.OrderBy(p => p.size); break; case "quantity_desc": sizes = sizes.OrderByDescending(p => p.quantity); break; case "quantity_asc": sizes = sizes.OrderBy(p => p.quantity); break; } } } this.aProducts.products = products.Skip((pPageInfor.pageIndex - 1) * pPageInfor.pageSize).Take(pPageInfor.pageSize); this.aProducts.sizes = sizes; if (func == "details") { this.aProducts.choosenProduct = db.Product.Where(p => p.id == id).FirstOrDefault(); this.aProducts.sizes = db.ProductSize.Where(s => s.product == this.aProducts.choosenProduct.id); this.aProducts.editedSize = new ProductSize(); } if (sizeId != 0 && sizeAlter != 0) { ProductSize sz = db.ProductSize.FirstOrDefault(s => s.id == sizeId); db.Entry(sz).State = Microsoft.EntityFrameworkCore.EntityState.Detached; sz.quantity = Convert.ToString((int.Parse(sz.quantity) + sizeAlter)); db.Update(sz); db.SaveChanges(); } if (func == "edit") { this.isCreation = false; this.aProducts.editedProduct = db.Product.FirstOrDefault(p => p.id == id); } else if (func == "delete") { Product pd = db.Product.FirstOrDefault(p => p.id == id); db.Product.Remove(pd); db.SaveChanges(); } else { this.isCreation = true; this.aProducts.editedProduct = new Product() { id = 0 }; } }
public IActionResult PersonalAccount(PersonalAccountVM accountVM) { Customer c = accountVM.customer; string first_name = accountVM.first_name; string last_name = accountVM.last_name; string new_password = accountVM.new_password; int date; int month; switch (accountVM.month) { case "January": month = 1; break; case "Febuary": month = 2; break; case "March": month = 3; break; case "April": month = 4; break; case "May": month = 5; break; case "June": month = 6; break; case "July": month = 7; break; case "August": month = 8; break; case "September": month = 9; break; case "October": month = 10; break; case "November": month = 11; break; case "December": default: month = 12; break; } switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: date = accountVM.date; break; case 4: case 6: case 9: case 11: if (accountVM.date > 30) { date = 30; } else { date = accountVM.date; } break; case 2: default: if (accountVM.date > 28) { date = 28; } else { date = accountVM.date; } break; } int year = accountVM.year; string gender = accountVM.gender; if (ModelState.IsValid) { if (accountVM.customer != null) { if (account.customer.id == 0) { Customer customer = new Customer(); customer.fullName = first_name + "_" + last_name; customer.email = c.email; customer.gender = gender == "Male" ? true : false; customer.password = new_password; DateTime birth = new DateTime(year, month, date); customer.birth = birth; customer.created = DateTime.Now; customer.closed = DateTime.Now; customer.username = accountVM.customer.username; db.Customer.Add(customer); db.SaveChanges(); } else { Customer customer = db.Customer.Where(_c => _c.id == account.customer.id).FirstOrDefault(); customer.fullName = first_name + "_" + last_name; customer.email = c.email; customer.gender = gender == "Male" ? true : false; if (new_password != "" || new_password != null) { customer.password = new_password; } DateTime birth = new DateTime(year, month, date); customer.birth = birth; customer.created = DateTime.Now; customer.closed = DateTime.Now; customer.username = accountVM.customer.username; Customer cus = db.Customer.FirstOrDefault(); db.Entry(cus).State = Microsoft.EntityFrameworkCore.EntityState.Detached; db.SaveChanges(); db.Customer.Update(customer); db.SaveChanges(); } } } account.new_password = ""; return(View(account)); }