Example #1
0
        public ActionResult AddNewOrder(NewOrderModel model)
        {
            Customer customer;
            int id = (int) Session["EmployeeId"];

            using (NorthwindConnection db = new NorthwindConnection())
            {
                customer = db.Customers.SingleOrDefault(x => x.CustomerID == model.Order.CustomerID);

                db.AddOrderTemporary(customer.CustomerID, id, model.Order.OrderDate, model.Order.RequiredDate,
                    model.Order.ShippedDate, model.Order.ShipVia, customer.CompanyName);
                db.SaveChanges();
            }


            return RedirectToAction("Index", "Home");
        }
Example #2
0
        public ActionResult ChangeAmount(int orderId, int productId, string change, short amount)
        {
            Order order;
            List<Order_Detail> orderDetail;
            Customer customer;
            List<Product> products;
            List<Category> categories;
            using (NorthwindConnection db = new NorthwindConnection())
            {
                categories = db.Categories.ToList();
                products = db.Products.ToList();
                order = db.Orders.SingleOrDefault(o => o.OrderID == orderId);
                orderDetail = GetOrderDetails(db, order.OrderID);
                    
                short quantity = orderDetail.SingleOrDefault(x => x.ProductID == productId).Quantity;
                if (change == "add")
                {
                    quantity += amount;
                }
                else
                {
                    if ((quantity - amount) > 0)
                    {
                        quantity -= amount;
                    }
                    else
                    {
                        quantity = 0;
                    }
                }
                if (quantity > 0)
                {
                    orderDetail.SingleOrDefault(x => x.ProductID == productId).Quantity = quantity;
                }
                else
                {
                    Order_Detail rowToRemove = orderDetail.SingleOrDefault(x => x.ProductID == productId);
                    orderDetail.Remove(rowToRemove);
                    db.DeleteOrderDetail(order.OrderID, productId);
                }
                customer = db.Customers.SingleOrDefault(c => c.CustomerID == order.CustomerID);
                db.SaveChanges();
            }

            OrderDetailsModel model = new OrderDetailsModel();
            model.Order = order;
            model.OrderDetails = orderDetail;
            model.Customer = customer;
            model.Products = products;
            model.categories = categories.Select(x => new SelectListItem()
            {
                Value = x.CategoryID.ToString(),
                Text = x.CategoryName
            });

            return PartialView("_OrderDetails", model);
        }
Example #3
0
        public ActionResult AddNewProduct(int productId, int orderId, short amount)
        {
            List<Order_Detail> orderDetails;
            using (NorthwindConnection db = new NorthwindConnection())
            {
                orderDetails = GetOrderDetails(db, orderId);
                bool isNew = true;
                foreach (var orderDetail in orderDetails)
                {
                    if (orderDetail.ProductID == productId)
                    {
                        isNew = false;
                    }
                }

                if (isNew)
                {
                    Product prod = db.Products.SingleOrDefault(x => x.ProductID == productId);
                    //Order order = db.Orders.SingleOrDefault(p => p.OrderID == orderId);
                    db.UpdateOrderDetails(orderId, productId, prod.UnitPrice, amount, 0);
                    db.SaveChanges();
                }
                else
                {
                    return RedirectToAction("ChangeAmount", new{orderId = orderId, productId = productId, change = "add", amount = amount});
                }
            }
            return RedirectToAction("OrderDetails", new{id = orderId});
        }
Example #4
0
        public ActionResult UpdateProfile(AccountDetailsModel m)
        {
            AccountDetailsModel model = m;
            if (m.UserType == "employee")
            {
                using (NorthwindConnection db = new NorthwindConnection())
                {
                    Employee e = db.Employees.SingleOrDefault(x => x.EmployeeID == m.Employee.EmployeeID);
                    
                    db.Employees.SingleOrDefault(x => x.EmployeeID == m.Employee.EmployeeID).FirstName =
                        m.Employee.FirstName;

                    db.Employees.SingleOrDefault(x => x.EmployeeID == m.Employee.EmployeeID).LastName =
                        m.Employee.LastName;
                    db.SaveChanges();

                }
            }
            else
            {
                using (NorthwindConnection db = new NorthwindConnection())
                {

                    db.Customers.SingleOrDefault(x => x.CustomerID == m.Customer.CustomerID).ContactName =
                        m.Customer.ContactName;

                    db.Customers.SingleOrDefault(x => x.CustomerID == m.Customer.CustomerID).ContactTitle =
                        m.Customer.ContactTitle;
                    db.SaveChanges();
                }
            }
            return View();
        }