public ActionResult Index(CustomerCustom model = null) { int i; if (model != null) { i = model.CurrentPageIndex; } model = new CustomerCustom { cust = db.Odbs.ToList(), custDDL = db.Odbs.ToList() }; var res = (from s in model.cust select s); res = res.ToList(); if (model.CurrentPageIndex == 0) { model.CurrentPageIndex = 0; } model.PageSize = 2; model.PageCount = ((res.Count() + model.PageSize - 1) / model.PageSize); if (model.CurrentPageIndex > model.PageCount) { model.CurrentPageIndex = model.PageCount; } model.cust = res.Skip(model.CurrentPageIndex * model.PageSize).Take(model.PageSize); return(View(model)); }
// GET: Opportunity public ActionResult Index(CustomerCustom model, string btn = null) { if (model.SortField == null) { model.SortField = "OCenter"; model.SortDirection = "ascending"; } #region SortData switch (model.SortField) { case "OCenter": model.cust = (model.SortDirection == "ascending" ? db.Odbs.OrderBy(c => c.OCenter) : db.Odbs.OrderByDescending(c => c.OCenter)); break; case "CustomerLastName": model.cust = (model.SortDirection == "ascending" ? db.Odbs.OrderBy(c => c.OSkills) : db.Odbs.OrderByDescending(c => c.OSkills)); break; } #endregion var ddl = (from d in model.cust select d); model.custDDL = ddl; #region FilterData if (!String.IsNullOrEmpty(model.SelectedFirstName)) { model.cust = model.cust.Where(s => s.OCenter.ToString().Trim().Equals(model.SelectedFirstName.Trim())); } if (!String.IsNullOrEmpty(model.SelectedLastName)) { model.cust = model.cust.Where(s => s.OSkills.ToString().Trim().Equals(model.SelectedLastName.Trim())); } #endregion var res = (from s in model.cust select s); res = res.ToList(); if (model.CurrentPageIndex == 0) { model.CurrentPageIndex = 0; } model.PageSize = 100; model.PageCount = ((res.Count() + model.PageSize - 1) / model.PageSize); if (model.CurrentPageIndex > model.PageCount) { model.CurrentPageIndex = model.PageCount; } model.cust = res.Skip(model.CurrentPageIndex * model.PageSize).Take(model.PageSize); return(View(model)); }
public ActionResult Register([Bind(Include = "id_customer,login,password")] CustomerCustom modelmodified) { Customer model = new Customer(); model.login = modelmodified.login; model.password = Encode(modelmodified.password); model.phone = "-"; model.adress_customer = "-"; model.roleid = 1; if (model.login != null && model.password != null) { Customer customer = db.Customers.FirstOrDefault(u => u.login == model.login); if (customer == null) { db.Customers.Add(model); db.SaveChanges(); customer = db.Customers.Where(u => u.login == model.login && u.password == model.password).FirstOrDefault(); // если пользователь удачно добавлен в бд if (customer != null) { FormsAuthentication.SetAuthCookie(model.login, true); return(RedirectToAction("Index", "Customers")); } } else { if (model.login != null) { ViewBag.login = "******"; } if (model.password != null) { ViewBag.password = "******"; } return(View()); } } return(View(model)); }
public string RegisterJson(CustomerCustom model) { ID answer = new ID(); answer.id_customer = 0; string jsonDefault = JsonConvert.SerializeObject(answer); if (model.login == null) { return(jsonDefault); } if (model.password == null) { return(jsonDefault); } if (model.phone == null) { return(jsonDefault); } if (model.phone.Length < 11) { return(jsonDefault); } if (model.adress_customer == null) { return(jsonDefault); } Customer customer = new Customer { id_customer = db.Customers.ToList().LastOrDefault().id_customer + 1, login = model.login, password = Encode(model.password), phone = model.phone, adress_customer = model.adress_customer, roleid = 2, role = null, requests = new List <Request>() }; if (db.Customers.Where(u => u.login == customer.login).FirstOrDefault() == null) { db.Customers.Add(customer); db.SaveChanges(); } else { answer.id_customer = -1; string json = JsonConvert.SerializeObject(answer); return(json); } Customer customer_db = db.Customers.Where(u => u.login == customer.login && u.password == customer.password).FirstOrDefault(); if (customer_db != null) { answer.id_customer = customer.id_customer; string json = JsonConvert.SerializeObject(answer); return(json); } else { answer.id_customer = -1; string json = JsonConvert.SerializeObject(answer); return(json); } }