public ManagementLoading() { using (QWDBEntities db = new QWDBEntities()) { var GetProducts = db.products.Where(x => x.ProductId > 0); var GetServices = db.services.Where(x => x.ServiceID > 0); var GetUsers = db.users.Where(x => x.Status == "Activo"); var GetOrders = db.orders.Where(x => x.OrderId > 0); foreach (var r in GetProducts) { products.Add(r); } foreach (var r in GetServices) { services.Add(r); } foreach (var r in GetUsers) { users.Add(r); } foreach (var r in GetOrders) { orders.Add(r); } } }
public OrdersLoading() { using (QWDBEntities db = new QWDBEntities()) { var GetOrder = db.orders.OrderByDescending(x => x.OrderId).First(); ord.OrderId = GetOrder.OrderId + 1; DateTime dt = DateTime.UtcNow.AddHours(-5); ord.Date = dt.ToShortDateString(); ord.Status = "Por Iniciar"; ord.ProductQ = 0; ord.ServiceQ = 0; ord.TotalPrice = 0; order = ord; var GetProducts = db.products.Where(x => x.ProductId > 0); var GetServices = db.services.Where(x => x.ServiceID > 0); foreach (var r in GetProducts) { products.Add(r); } foreach (var r in GetServices) { services.Add(r); } } }
public ActionResult Login(user usermodel) { using (QWDBEntities db = new QWDBEntities()) { var UserConfirmation = db.users.Where(x => x.Email == usermodel.Email && x.Password == usermodel.Password).FirstOrDefault(); if (UserConfirmation == null) { usermodel.LoginError = "Email o Contraseña Incorrectos"; usermodel.Password = null; return(View("IndexW", usermodel)); } else { Session["id"] = UserConfirmation.UserID; Session["email"] = UserConfirmation.Email; Session["name"] = UserConfirmation.Name; Session["position"] = UserConfirmation.Position; if (UserConfirmation.Position == "Administrador") { return(RedirectToAction("Index", "Management")); } else { return(RedirectToAction("Index", "Employee")); } } } }
public ViewOrderLoading(int id) { using (QWDBEntities db = new QWDBEntities()) { order = db.orders.Find(id); var GetOrderpDetails = db.orderpdetails.Where(x => x.OrderId == id); var GetOrdersDetails = db.ordersdetails.Where(x => x.OrderId == id); foreach (var p in GetOrderpDetails) { orderpdetails.Add(p); } foreach (var s in GetOrdersDetails) { ordersdetails.Add(s); } foreach (var p in orderpdetails) { var GetProduct = db.products.Find(p.Productid); products.Add(GetProduct); } foreach (var s in ordersdetails) { var GetService = db.services.Find(s.ServiceId); services.Add(GetService); } } }
public ActionResult AddOrd() { using (QWDBEntities db = new QWDBEntities()) { try{ int uid = (int)Session["id"]; var OrderCreation = db.Set <order>(); OrderCreation.Add(new order { CustomerId = OrdersLoading.ord.CustomerId, Date = OrdersLoading.ord.Date, ProductQ = OrdersLoading.ord.ProductQ, ServiceQ = OrdersLoading.ord.ServiceQ, Status = OrdersLoading.ord.Status, TotalPrice = OrdersLoading.ord.TotalPrice, UserId = uid }); db.SaveChanges(); foreach (var p in DetailsLists.ordpd) { db.Database.ExecuteSqlCommand("INSERT INTO orderpdetails VALUES (" + p.OrderId + "," + p.Productid + "," + p.Quantity + "," + p.Price + ")"); db.SaveChanges(); } foreach (var s in DetailsLists.ordsd) { db.Database.ExecuteSqlCommand("INSERT INTO ordersdetails VALUES (" + s.OrderId + "," + s.ServiceId + "," + s.Price + ")"); db.SaveChanges(); } return(RedirectToAction("GetOrders")); } catch { return(new EmptyResult()); } } }
public ActionResult AddPro(product productmodel) { using (QWDBEntities db = new QWDBEntities()) { try { int idp; product LastProduct; try { LastProduct = db.products.Where(x => x.ProductId > 0).OrderByDescending(x => x.ProductId).First(); idp = LastProduct.ProductId + 1; } catch { idp = 1; } var ProductCreation = db.Set <product>(); ProductCreation.Add(new product { ProductId = idp, Name = productmodel.Name, Price = productmodel.Price, Quantity = productmodel.Quantity }); db.SaveChanges(); return(RedirectToAction("GetProducts", "Management")); } catch (Exception ex) { productmodel.AddPError = "Couldn't create new Product" + ex; return(PartialView("_ProAdd", productmodel)); } } }
public ActionResult AddSer(service servicemodel) { using (QWDBEntities db = new QWDBEntities()) { try { int ids; service LastService; try { LastService = db.services.Where(x => x.ServiceID > 0).OrderByDescending(x => x.ServiceID).First(); ids = LastService.ServiceID + 1; } catch { ids = 1; } var ServiceCreation = db.Set <service>(); ServiceCreation.Add(new service { ServiceID = ids, Name = servicemodel.Name, Price = servicemodel.Price }); db.SaveChanges(); return(RedirectToAction("GetServices", "Management")); } catch (Exception ex) { servicemodel.AddSError = "Couldn't create new Service" + ex; return(PartialView("_SerAdd", servicemodel)); } } }
public ActionResult AddSDet(ordersdetail ordersdetailmodel, int id) { ordersdetailmodel.OrderId = id; using (QWDBEntities db = new QWDBEntities()) { var GetServicePrice = db.services.Find(ordersdetailmodel.ServiceId).Price; ordersdetailmodel.Price = GetServicePrice; } DetailsLists.ordsd.Add(ordersdetailmodel); return(PartialView("_AddedDet", detailsLists())); }
public ActionResult AddPDet(orderpdetail orderpdetailmodel, int id) { orderpdetailmodel.OrderId = id; using (QWDBEntities db = new QWDBEntities()) { var GetProductPrice = db.products.Find(orderpdetailmodel.Productid).Price; orderpdetailmodel.Price = GetProductPrice * orderpdetailmodel.Quantity; } DetailsLists.ordpd.Add(orderpdetailmodel); return(PartialView("_AddedDet", detailsLists())); }
public ActionResult UpdateUsr(user usermodel) { using (QWDBEntities db = new QWDBEntities()) { if (ModelState.IsValid) { db.Entry(usermodel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("GetUsers")); } else { usermodel.AddUError = "Couldn't edit User"; return(PartialView("_UsrEdit", usermodel)); } } }
public ActionResult UpdateSer(service servicemodel) { using (QWDBEntities db = new QWDBEntities()) { if (ModelState.IsValid) { db.Entry(servicemodel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("GetServices")); } else { servicemodel.AddSError = "Couldn't edit Service"; return(PartialView("_SerEdit", servicemodel)); } } }
public ActionResult UpdatePro(product productmodel) { using (QWDBEntities db = new QWDBEntities()) { if (ModelState.IsValid) { db.Entry(productmodel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("GetProducts")); } else { productmodel.AddPError = "Couldn't edit Product"; return(PartialView("_ProEdit", productmodel)); } } }
public DetailsLists() { int acup = 0, acus = 0; double prip = 0, pris = 0; orderpdetails = ordpd; ordersdetails = ordsd; foreach (var p in orderpdetails) { acup += p.Quantity; prip += p.Price; } foreach (var s in ordersdetails) { acus++; pris += s.Price; } OrdersLoading.ord.ProductQ = acup; OrdersLoading.ord.ServiceQ = acus; OrdersLoading.ord.TotalPrice = prip + pris; order = OrdersLoading.ord; using (QWDBEntities db = new QWDBEntities()) { foreach (var p in orderpdetails) { var GetProduct = db.products.Find(p.Productid); products.Add(GetProduct); } foreach (var s in ordersdetails) { var GetService = db.services.Find(s.ServiceId); services.Add(GetService); } var GetProducts = db.products.Where(x => x.ProductId > 0); var GetServices = db.services.Where(x => x.ServiceID > 0); foreach (var r in GetProducts) { productsopt.Add(r); } foreach (var r in GetServices) { servicesopt.Add(r); } } }
public ActionResult AddUsr(user usermodel) { using (QWDBEntities db = new QWDBEntities()) { try { var UserCreation = db.Set <user>(); UserCreation.Add(new user { UserID = usermodel.UserID, Email = usermodel.Email, Password = usermodel.Password, Name = usermodel.Name, Position = usermodel.Position, Status = "Activo" }); db.SaveChanges(); return(RedirectToAction("GetUsers", "Management")); } catch (Exception ex) { usermodel.AddUError = "Couldn't create new User" + ex; return(PartialView("_UsrAdd", usermodel)); } } }