// GET: Orders/Create public ActionResult Create() { var user = db.Users. Where(us => us.UserName == User.Identity.Name). FirstOrDefault(); ViewBag.CustomerId = new SelectList( ComboBoxHelpers. GetCustomers( user.CompanyId), "CustomerID", "FullName"); var newView = new NewOrderView { DateOrder = DateTime.Now, Details = db.OrderDetailTmps. Where(odt => odt.UserName == User.Identity.Name). ToList(), }; return(View(newView)); }
// GET: OrderHeaders/Create public ActionResult Create(int?id) { var view = new NewOrderView { Date = DateTime.Now, NeedByDate = DateTime.Now }; ViewBag.UserId = new SelectList(db.Users, "UserId", "FirstName"); var v = db.NewOrderView.Where(o => o.UserId == 1).FirstOrDefault(); if (v != null) { ViewBag.CustomerId = new SelectList(db.Customers.Where(c => c.VendorId == 74 && c.CustomerId == v.CustomerId), "CustomerId", "Names"); ViewBag.ShipToId = new SelectList(db.ShipToes.Where(c => c.VendorId == 74), "ShipToId", "ShipToName", v.ShipToId); ViewBag.ContactId = new SelectList(db.Contacts.Where(c => c.VendorId == 74 && c.ShipToId == v.ShipToId), "ContactId", "Name", v.ContactId); ViewBag.PriceListId = new SelectList(CombosHelper.GetPriceList(v.CustomerId).OrderBy(P => P.PriceListId), "PriceListId", "ListDescription", v.PriceListId); view = v; } else { ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomer(74), "CustomerId", "Names"); ViewBag.ShipToId = new SelectList(CombosHelper.GetShipto(74), "ShipToId", "ShipToName"); ViewBag.ContactId = new SelectList(CombosHelper.GetContact(74), "ContactId", "Name"); ViewBag.PriceListId = new SelectList(db.PriceLists.OrderBy(P => P.PriceListId), "PriceListId", "ListDescription"); } view.OrderDetails = db.OrderDetailTmp.Where(o => o.UserId == 1).ToList(); //ViewBag.ShipToId = new SelectList(db.ShipToes.Where(c => c.VendorId == 74 && c.CustomerId == db.Customers.FirstOrDefault().CustomerId).OrderBy(c => c.ShipToName), "ShipToId", "ShipToName"); //ViewBag.ContactId = new SelectList(db.Contacts.Where(c => c.VendorId == 74 && c.ShipToId == db.ShipToes.FirstOrDefault().ShipToId).OrderBy(c => c.Name), "ContactId", "Name"); //ViewBag.PriceListId = new SelectList(db.PriceLists.Where(p => p.PriceListId == 0).OrderBy(P => P.PriceListId), "PriceListId", "ListDescription"); return(View(view)); }
public ActionResult Create() { var adminUser = WebConfigurationManager.AppSettings["AdminUser"]; if (adminUser == User.Identity.Name) { ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomers(), "CustomerId", "FullName"); ViewBag.ProjectId = new SelectList(CombosHelper.GetProjects(0), "ProjectId", "Name"); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name"); var adminView = new NewOrderView { Date = DateTime.Now, Details = db.OrderDetailTmps.Where(odt => odt.UserName == User.Identity.Name).ToList(), }; return(View(adminView)); } //verifica el usuario logeado y envia su compania a la vista var user = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); if (user == null) { return(RedirectToAction("Index", "Home")); } ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomers(), "CustomerId", "FullName"); ViewBag.ProjectId = new SelectList(CombosHelper.GetProjects(user.CompanyId), "ProjectId", "Name"); var view = new NewOrderView { CompanyId = user.CompanyId, Date = DateTime.Now, Details = db.OrderDetailTmps.Where(odt => odt.UserName == User.Identity.Name).ToList(), }; return(View(view)); }
public ActionResult Create(NewOrderView view) { if (ModelState.IsValid) { using (var transaction = db.Database.BeginTransaction()) { try { var order = new Order { Date = view.Date, ClientId = view.ClientId, CellarId = view.CellarId, RouteId = view.RouteId, StateId = 1 }; db.Orders.Add(order); db.SaveChanges(); var detailbks = db.OrderDetailBkps.Where(pdb => pdb.User == User.Identity.Name).ToList(); foreach (var detail in detailbks) { var orderDetail = new OrderDetail { OrderId = order.OrderId, ProductId = detail.ProductId, Description = detail.Description, Price = detail.Price, Quantity = detail.Quantity }; var bodega = db.CellarProducts.Where(cp => cp.ProductId == detail.ProductId).FirstOrDefault(); bodega.Stock -= detail.Quantity; db.Entry(bodega).State = EntityState.Modified; db.OrderDetails.Add(orderDetail); db.OrderDetailBkps.Remove(detail); } db.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); ModelState.AddModelError(string.Empty, ex.Message); } } return(RedirectToAction("Index")); } ViewBag.CellarId = new SelectList(db.Cellars, "CellarId", "Description", view.CellarId); ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "ComertialName", view.ClientId); ViewBag.RouteId = new SelectList(db.Routes, "RouteId", "RouteNumber", view.RouteId); view.Details = db.OrderDetailBkps.Where(pdb => pdb.User == User.Identity.Name).ToList(); return(View(view)); }
public ActionResult Create(NewOrderView order) { if (ModelState.IsValid) { var response = MovementsHelper.NewOrder(order, User.Identity.Name); if (response.Succeeded) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, response.Message); } var adminUser = WebConfigurationManager.AppSettings["AdminUser"]; if (adminUser == User.Identity.Name) { ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomers(), "CustomerId", "UserName", order.CustomerId); ViewBag.ProjectId = new SelectList(CombosHelper.GetProjects(order.CompanyId), "ProjectId", "Name", order.ProjectId); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", order.CompanyId); } else { var user = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name); ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomers(user.CompanyId), "CustomerId", "UserName", order.CustomerId); ViewBag.ProjectId = new SelectList(CombosHelper.GetProjects(user.CompanyId), "ProjectId", "Name", order.ProjectId); } order.Details = db.OrderDetailTmps.Where(odt => odt.UserName == User.Identity.Name).ToList(); return(View(order)); }
public void NewOrder(NewOrderView view) { var logItem = String.Format("Customer {0} ordered {1} - {2}.", view.CustomerName, view.Drink, view.DrinkSize); Invoke(new Action <String>(Log), logItem); }
public static Response NewOrder(NewOrderView view, string UserName) { using (var transacction = db.Database.BeginTransaction()) { try { var user = db.Users.Where(u => u.UserName == UserName).FirstOrDefault(); var order = new Order { CompanyId = user.CompanyId, CustomerId = view.CustomerId, Date = view.Date, Remarks = view.Remarks, StateId = DBHelper.GetState("Created", db) }; db.Order.Add(order); db.SaveChanges(); var details = db.OrderDetailTmps.Where(odt => odt.UserName == UserName).ToList(); foreach (var detail in details) { var orderDetail = new OrderDetail { Description = detail.Description, OrderId = order.OrderId, Price = detail.Price, ProductId = detail.ProductId, Quantity = detail.Quantity, TaxRate = detail.TaxRate }; db.OrderDetails.Add(orderDetail); db.OrderDetailTmps.Remove(detail); } db.SaveChanges(); transacction.Commit(); return(new Response { Succeeded = true }); } catch (Exception ex) { transacction.Rollback(); return(new Response { Message = ex.Message, Succeeded = false }); } } }
public static Response NewOrder(NewOrderView view, string userName) { using (var transacction = db.Database.BeginTransaction()) {//es una transaccion try { var user = db.Users.Where(u => u.UserName == userName).FirstOrDefault(); var order = new Order { CompanyId = user.CompanyId, CustomerId = user.CompanyId, Date = view.Date, Remarks = view.Remarks, StateId = DBHelper.GetState("Create", db)//estado en contexto db }; db.Orders.Add(order); db.SaveChanges(); //despues de la orden debemos consultar cuales son los detalles de ese cliente para tirarlo a la tabla temporal // var details = db.OrderDetailTmps.Where(odt => odt.UserName == userName).ToList(); var details = db.OrderDetailTmps.Where(odt => odt.UserName == userName).ToList(); foreach (var detail in details) { var orderDetail = new OrderDetail { Description = detail.Description, OrderId = order.OrderId, Price = detail.Price, ProductId = detail.ProductId, Quantity = detail.Quantity, TaxRate = detail.TaxRate }; db.OrderDetails.Add(orderDetail); db.OrderDetailTmps.Remove(detail); } db.SaveChanges(); transacction.Commit(); return(new Response { Succeeded = true, }); } catch (Exception ex) { transacction.Rollback(); return(new Response { Message = ex.Message, Succeeded = false, }); } } }
private void OrderItem(object sender, EventArgs e) { // Létrehozzuk az új megrendelés nézetet NewOrderView newOrderView = new NewOrderView { Owner = _View.Form, ItemId = _View.SelectedItem.item_id }; newOrderView.Show(); }
public async Task <IActionResult> New() { var model = new NewOrderView(); model.Order = new ResourceOrder(); model.Department = _departmentsService.GetDepartmentById(DepartmentId); model.Order.NeededBy = DateTime.UtcNow.AddDays(30); model.Order.NeededBy = new DateTime(model.Order.NeededBy.Year, model.Order.NeededBy.Month, model.Order.NeededBy.Day, model.Order.NeededBy.Hour, 0, 0, model.Order.NeededBy.Kind); return(View(model)); }
//Returns the ID of the new order public int AddOrder(NewOrderView order) { Order orderEntity = new Order { CustomerID = order.OwnerID, ShippingCost = order.ShippingCost }; var derp = _db.Add(orderEntity); _db.SaveChanges(); return(derp.Entity.ID); }
// GET: Orders/Create public ActionResult Create() { var user = db.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.CustomerID = new SelectList(comboHelper.GetCustomers(user.CompanyID), "CustomerID", "FullName"); var view = new NewOrderView { Date = DateTime.Now, Details = db.OrderDetailTemps.Where(o => o.UserName == User.Identity.Name).ToList(), }; return(View(view)); }
// GET: Orders/Create public ActionResult Create() { var user = db.Users.Where(u => u.UserName.Equals(User.Identity.Name)).FirstOrDefault(); ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomer(user.CompanyId), "CustomerId", "FullName"); //ViewBag.StateId = new SelectList(db.States, "StateId", "Description"); var view = new NewOrderView { Date = DateTime.Now, Details = db.OrderDetailTmps.Where(odt => odt.UserName.Equals(User.Identity.Name)).ToList() }; return(View(view)); }
// GET: Orders/Create public ActionResult Create() { ViewBag.CellarId = new SelectList(db.Cellars.OrderBy(b => b.Description), "CellarId", "Description"); ViewBag.ClientId = new SelectList(db.Clients.OrderBy(cl => cl.ComertialName), "ClientId", "ComertialName"); ViewBag.RouteId = new SelectList(db.Routes.OrderBy(rt => rt.RouteNumber), "RouteId", "RouteNumber"); var view = new NewOrderView { Date = DateTime.Now, Details = db.OrderDetailBkps.Where(pdb => pdb.User == User.Identity.Name).ToList() }; return(View(view)); }
public ActionResult AddProduct(int PriceListId, int?SalesOrderHeaderId, int CustomerId, int ShipToId, int ContactId, DateTime Date, DateTime NeedByDate, string Observations, string Terms) { if (SalesOrderHeaderId == null || SalesOrderHeaderId == 0) { var customer = db.Customers.Where(c => c.CustomerId == CustomerId).FirstOrDefault(); var shipto = db.ShipToes.Where(s => s.ShipToId == ShipToId).FirstOrDefault(); var contact = db.Contacts.Where(c => c.ContactId == ContactId).FirstOrDefault(); var view = new NewOrderView { SalesOrderHeaderId = 0, ConNum = contact.ConNum, ContactId = contact.ContactId, CreditHold = customer.CreditHold, CustId = customer.CustId, CustomerId = customer.CustomerId, Observations = Observations, OrderNum = 0, Platform = "WEB", PriceListId = PriceListId, RowMod = "C", SalesOrderHeaderInterId = 0, ShipToId = shipto.ShipToId, ShipToNum = shipto.ShipToNum, UserId = 1, VendorId = 74, Date = Date, NeedByDate = NeedByDate, TermsCode = Terms }; MovementsHelper.CreateNewOrderNew(view); } else { var view = db.NewOrderView.Find(SalesOrderHeaderId); view.PriceListId = PriceListId; view.Date = Date; view.Observations = Observations; view.NeedByDate = NeedByDate; db.SaveChanges(); } //var CustomerPriceList = db.CustomerPriceLists.Where(c => c.CustomerId == CustomerID).OrderBy(c => c.CustomerId).ToList(); ViewBag.PriceListId = new SelectList(db.PriceLists.Where(p => p.PriceListId == PriceListId), "PriceListId", "ListDescription", PriceListId); ViewBag.PartId = new SelectList(CombosHelper.GetPriceListPart(PriceListId), "PartId", "PartDescription"); //ViewBag.PriceListPartId= return(View()); }
public ActionResult Create(NewOrderView view) { if (ModelState.IsValid) { var response = MovementsHelper.NewOrder(view, User.Identity.Name); if (response.Succeeded) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, response.Message); } var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomers(user.CompanyId), "CustomerId", "FullName"); view.Details = db.OrderDetailTmps.Where(odt => odt.UserName == User.Identity.Name).ToList(); return(View(view)); }
public ActionResult Create(NewOrderView view)// { view.RowMod = "C"; view.Platform = "WEB"; view.SalesCategory = "Bogota"; if (view.CustId == null && view.CustomerId != 0) { var customer = db.Customers.Where(c => c.CustomerId == view.CustomerId).FirstOrDefault(); view.CustId = customer.CustId; } else { ModelState.AddModelError(String.Empty, "Seleccione un cliente"); } if (view.ShipToNum == null && view.ShipToId != 0) { var shipto = db.ShipToes.Where(s => s.ShipToId == view.ShipToId).FirstOrDefault(); view.ShipToNum = shipto.ShipToNum; } if (view.ConNum == 0 && view.ContactId != 0) { var contact = db.Contacts.Where(c => c.ContactId == view.ContactId).FirstOrDefault(); view.ConNum = contact.ConNum; } view.OrderDetails = db.OrderDetailTmp.Where(o => o.UserId == 1).ToList(); var response = MovementsHelper.NewOrder(view, 1); if (response.Succes) { return(RedirectToAction("Index")); } ModelState.AddModelError(String.Empty, response.Message); //db.OrderHeaders.Add(orderHeader); //db.SaveChanges(); view.OrderDetails = db.OrderDetailTmp.Where(o => o.UserId == 1).ToList(); ViewBag.ContactId = new SelectList(db.Contacts, "ContactId", "Name", view.ContactId); ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "Names", view.CustomerId); ViewBag.ShipToId = new SelectList(db.ShipToes, "ShipToId", "ShipToName", view.ShipToId); ViewBag.UserId = new SelectList(db.Users, "UserId", "FirstName", view.UserId); ViewBag.PriceListId = new SelectList(db.PriceLists.OrderBy(P => P.PriceListId), "PriceListId", "ListDescription"); //return RedirectToAction("Create", view); return(View(view)); }
public ActionResult Create(NewOrderView view) { if (ModelState.IsValid) { Response response = MovementsHelper.NewOrder(view, User.Identity.Name); if (response.Succeeded) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, response.Message); } var user = db.Users.Where(c => c.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomers(user.CompanyId), "CustomerId", "FullName", view.CustomerId); //ViewBag.StateId = new SelectList(db.States, "StateId", "Description", order.StateId); return(View(view)); }
// GET: Orders/Create public ActionResult Create() { var user = db.Users.Where(c => c.UserName == User.Identity.Name).FirstOrDefault(); if (user == null) { return(RedirectToAction("Index", "Home")); } ViewBag.CustomerId = new SelectList(CombosHelper.GetCustomers(user.CompanyId), "CustomerId", "FullName"); //ViewBag.StateId = new SelectList(db.States, "StateId", "Description"); var view = new NewOrderView { Date = DateTime.Now, Details = db.OrderDetailTmps.Where(odt => odt.UserName == User.Identity.Name).ToList(), }; view.Details = db.OrderDetailTmps.Where(odt => odt.UserName == User.Identity.Name).ToList(); return(View(view)); }
public async Task <IActionResult> New(NewOrderView model, IFormCollection form) { if (ModelState.IsValid) { var settings = await _resourceOrdersService.GetSettingsByDepartmentId(DepartmentId); List <int> questions = (from object key in form.Keys where key.ToString().StartsWith("itemResource_") select int.Parse(key.ToString().Replace("itemResource_", ""))).ToList(); if (questions.Count > 0) { model.Order.Items = new Collection <ResourceOrderItem>(); } foreach (var i in questions) { if (form.ContainsKey("itemResource_" + i)) { var resourceText = form["itemResource_" + i]; var resourceMin = form["itemMin_" + i]; var resourceMax = form["itemMax_" + i]; var resourceCode = form["itemFinancial_" + i]; var resourceNeeds = form["itemNeeds_" + i]; var resourceRequirements = form["itemRequirements_" + i]; var item = new ResourceOrderItem(); item.Resource = resourceText; int minimum = 0; if (int.TryParse(resourceMin, out minimum)) { item.Min = minimum; } if (minimum == 0) { item.Min = 1; } int maxiumum = 0; if (int.TryParse(resourceMax, out maxiumum)) { item.Max = maxiumum; } if (minimum > maxiumum) { item.Max = item.Min; } if (item.Max == 0) { item.Max = item.Min; } item.FinancialCode = resourceCode; item.SpecialNeeds = resourceNeeds; item.Requirements = resourceRequirements; model.Order.Items.Add(item); } } model.Order.DepartmentId = DepartmentId; model.Order.OpenDate = DateTime.UtcNow; var department = _departmentsService.GetDepartmentById(DepartmentId); var mapCenterLocation = _departmentSettingsService.GetMapCenterCoordinates(department); model.Order.OriginLatitude = mapCenterLocation.Latitude; model.Order.OriginLongitude = mapCenterLocation.Longitude; if (settings != null) { model.Order.Visibility = settings.Visibility; model.Order.Range = settings.Range; } else { model.Order.Visibility = 0; model.Order.Range = 500; } await _resourceOrdersService.CreateOrder(model.Order); return(RedirectToAction("Index")); } return(View(model)); }
public static Response NewOrder(NewOrderView newOrder, string userName) { using (var transacction = db.Database.BeginTransaction()) { try { var user = db.Users.FirstOrDefault(u => u.UserName == userName); int companyId; var adminUser = WebConfigurationManager.AppSettings["AdminUser"]; if (adminUser == userName) { companyId = newOrder.CompanyId; } else { companyId = user.CompanyId; } var order = new Order { CompanyId = companyId, CustomerId = newOrder.CustomerId, ProjectId = newOrder.ProjectId, Date = newOrder.Date, Remarks = newOrder.Remarks, OrderStateId = DBHelper.GetOrderState("Created", db), }; db.Orders.Add(order); db.SaveChanges(); var details = db.OrderDetailTmps.Where(odt => odt.UserName == userName).ToList(); foreach (var orderDetailTmp in details) { var orderDetail = new OrderDetail { Description = orderDetailTmp.Description, OrderId = order.OrderId, Price = orderDetailTmp.Price, ProductId = orderDetailTmp.ProductId, Quantity = orderDetailTmp.Quantity, TaxRate = orderDetailTmp.TaxRate, }; db.OrderDetails.Add(orderDetail); db.OrderDetailTmps.Remove(orderDetailTmp); } db.SaveChanges(); transacction.Commit(); return(new Response { Succeeded = true }); } catch (Exception ex) { transacction.Rollback(); return(new Response { Message = ex.Message, Succeeded = false }); } } }