Example #1
0
        public ActionResult Create(IFormCollection collection, Models.Orders order)
        {
            var custID = HttpContext.Session.GetInt32("CustomerId");

            ViewBag.CustID = custID;
            PizzaProject1.Library.Orders dmc = new Orders();
            dmc.CustomerId   = custID;
            dmc.OrderId      = order.OrderId;
            dmc.RestaurantId = order.RestaurantId;
            dmc.TotalCost    = order.TotalCost;
            dmc.OrderDate    = order.OrderDate;

            try
            {
                // TODO: Add insert logic here

                //return RedirectToAction(nameof(Index));
                var OrdersID = HttpContext.Session.GetInt32("OrdersId");
                ViewBag.OrderID = OrdersID;
                db.AddOrders(dmc);
                db.Save();
                return(RedirectToAction("Index", "Orders"));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return(View());
            }
        }
Example #2
0
 public static DataAccess.Orders Map(Models.Orders orders) => new DataAccess.Orders
 {
     Id         = orders.Id,
     TotalDue   = orders.TotalDue,
     OrderTime  = orders.OrderTime,
     PizzaOrder = Map(orders.PizzaOrder).ToList()
 };
        public ActionResult Create(Models.Orders order)
        {
            if (!ModelState.IsValid)
            {
                return(View(order));
            }

            var productPrice = (from p in db.Products
                                where p.Id == order.ProductID
                                select p.Sell_price).First();

            order.Price = productPrice * order.Product_quantity;

            var customer = (from c in db.Customers
                            where c.Id == order.CustomerID
                            select c).First();

            if (order.Price < 2000 && !customer.Regular_customer)
            {
                order.Delivery_price = 120;
            }


            db.Orders.Add(order);
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(View(order));
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult Create(Models.Orders orders)
        {
            dicQtyOrder = new Dictionary <decimal, int>();
            try
            {
                if (ModelState.IsValid)
                {
                    Repo.AddCustomer(new Customers
                    {
                        Name  = orders.custName,
                        Phone = orders.custPhone
                    });
                    Repo.Save();

                    Repo.AddOrders(new Orders
                    {
                        orderDate    = DateTime.Now,
                        cutomerID    = Repo.GetLastCust().Id,
                        restaurantID = restID,
                        CostTotal    = 0
                    });
                    Repo.Save();

                    return(RedirectToAction(nameof(ProductsList)));
                }
                return(View(orders));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult OrdersDetails(int id)
        {
            Orders libOrder = Repo.GetOrdersById(id);

            var listPro = Repo.GetAllOrderProducts(id).ToList();

            //int num = dicQtyOrder[Repo.GetProductById(y.Id).Cost];

            var webRest = new Models.Orders
            {
                Id         = libOrder.Id,
                orderTotal = libOrder.CostTotal,
                orderDate  = libOrder.orderDate,
                custName   = Repo.GetCustomerById(libOrder.cutomerID).Name,
                custPhone  = Repo.GetCustomerById(libOrder.cutomerID).Phone,

                products = listPro.Select(y => new Models.Product
                {
                    productName = Repo.GetProductById(y.Id).Name,
                    Type        = Repo.GetProductById(y.Id).Type,
                    TotalCost   = Repo.GetProductById(y.Id).Cost,
                    QtyOrder    = dicQtyOrder[Repo.GetProductById(y.Id).Cost]
                }),
            };

            return(View(webRest));
        }
Example #6
0
        public string AddOrder([FromBody] Models.Orders order)
        {
            var status = "Adding order failed";

            try
            {
                EFModels.Orders petb = new EFModels.Orders()
                {
                    Orderid      = order.Orderid,
                    Userid       = order.Userid,
                    Itemid       = order.Itemid,
                    Dt           = order.Dt,
                    Quantity     = order.Quantity,
                    Status       = order.Status,
                    Method       = order.Method,
                    Total        = order.Total,
                    SrOrderid    = order.SrOrderid,
                    SrShipmentid = order.SrShipmentid
                };

                status = _UserFacade.AddOrder(petb);
            }
            catch (Exception e)
            {
                status = e.Message;
                throw e;
            }
            return(status);
        }
        public ActionResult Edit(Models.Orders order)
        {
            if (!ModelState.IsValid)
            {
                return(View(order));
            }

            var originalOrder = (from o in db.Orders
                                 where o.Id == order.Id
                                 select o).First();

            var productPrice = (from p in db.Products
                                where p.Id == order.ProductID
                                select p.Sell_price).First();

            order.Price = productPrice * order.Product_quantity;

            if (order.Price < 2000)
            {
                order.Delivery_price = 120;
            }

            db.Entry(originalOrder).CurrentValues.SetValues(order);
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(View(order));
            }
            return(RedirectToAction("Index"));
        }
Example #8
0
        public IHttpActionResult PostOrders(Models.Orders orders)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Orders.Add(orders);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (OrdersExists(orders.OrdId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = orders.OrdId }, orders));
        }
Example #9
0
        /// <summary>
        /// RESTful web service to POST orders.
        /// [Download the YAML for this call](API_processOrders.yaml)
        /// </summary>
        /// <param name="request">Required parameter: Example: </param>
        /// <return>Returns the Models.SalesOrderResponse response from the API call</return>
        public Models.SalesOrderResponse CreateSalesOrderWebService(Models.Orders request)
        {
            Task <Models.SalesOrderResponse> t = CreateSalesOrderWebServiceAsync(request);

            APIHelper.RunTaskSynchronously(t);
            return(t.Result);
        }
Example #10
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Orders = await _context.Orders
                     .Include(o => o.BackorderOrder)
                     .Include(o => o.ContactPerson)
                     .Include(o => o.Customer)
                     .Include(o => o.LastEditedByNavigation)
                     .Include(o => o.PickedByPerson)
                     .Include(o => o.SalespersonPerson).FirstOrDefaultAsync(m => m.OrderId == id);

            if (Orders == null)
            {
                return(NotFound());
            }
            ViewData["BackorderOrderId"]    = new SelectList(_context.Orders, "OrderId", "OrderId");
            ViewData["ContactPersonId"]     = new SelectList(_context.People, "PersonId", "FullName");
            ViewData["CustomerId"]          = new SelectList(_context.Customers, "CustomerId", "CustomerName");
            ViewData["LastEditedBy"]        = new SelectList(_context.People, "PersonId", "FullName");
            ViewData["PickedByPersonId"]    = new SelectList(_context.People, "PersonId", "FullName");
            ViewData["SalespersonPersonId"] = new SelectList(_context.People, "PersonId", "FullName");
            return(Page());
        }
Example #11
0
        public List <Models.Orders> GetRecentOrders(int num)
        {
            var retobj = new List <Models.Orders>();

            try
            {
                var repobj = _AdminFacade.GetRecentOrders(num);
                if (repobj != null)
                {
                    foreach (var order in repobj)
                    {
                        var iter = new Models.Orders
                        {
                            Orderid      = order.Orderid,
                            Userid       = order.Userid,
                            Itemid       = order.Itemid,
                            Dt           = order.Dt,
                            Quantity     = order.Quantity,
                            Status       = order.Status,
                            Method       = order.Method,
                            Total        = order.Total,
                            SrOrderid    = order.SrOrderid,
                            SrShipmentid = order.SrShipmentid
                        };
                        retobj.Add(iter);
                    }
                }
            }
            catch (Exception e)
            {
                retobj = null;
                throw e;
            }
            return(retobj);
        }
Example #12
0
        public IHttpActionResult PutOrders(string id, Models.Orders orders)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != orders.OrdId)
            {
                return(BadRequest());
            }

            db.Entry(orders).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrdersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public void AddNewOrder(Models.Orders Order)
 {
     using (DBContext db = new DBContext())
     {
         try
         {
             if (Order != null)
             {
                 db.Orders.Attach(Order);
                 db.Orders.Add(Order);
                 db.SaveChanges();
             }
         }
         catch (DbEntityValidationException ex)
         {
             foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
             {
                 Console.WriteLine("Object: " + validationError.Entry.Entity.ToString());
                 Console.WriteLine("");
                 foreach (DbValidationError err in validationError.ValidationErrors)
                 {
                     Console.WriteLine(err.ErrorMessage + "");
                 }
             }
         }
     }
 }
        public void Add(lib.Orders order)
        {
            _logger.Info("Adding Order");

            Models.Orders entity = Mapper.LibOrdersMap(order);
            _dbContext.Add(entity);
        }
Example #15
0
        // GET: Order
        public ActionResult Index()
        {
            var custID = HttpContext.Session.GetInt32("CustomerId");

            ViewBag.CustID = custID;

            var orders = db.GetOrders();

            foreach (var order in orders)
            {
                if (order.CustomerId == custID)
                {
                    c = new Models.Orders();

                    c.OrderId      = order.OrderId;
                    c.RestaurantId = order.RestaurantId;
                    c.CustomerId   = order.CustomerId;
                    c.TotalCost    = order.TotalCost;
                    c.OrderDate    = order.OrderDate;
                    ordersList.Add(c);
                }
            }

            return(View(ordersList));
        }
Example #16
0
 public static DTO.Orders ToDTO(this Models.Orders o)
 {
     return(new DTO.Orders
     {
         Id = o.Id,
         UserID = o.UserId,
     });
 }
        //Orders

        public void AddOrders(Models.Orders orders)
        {
            //if (_data.Any(r => r.Id == restaurant.Id))
            //{
            //    throw new InvalidOperationException($"Restaurant located at {restaurant.Location} already exists.");
            //}
            _db.Add(Mapper.Map(orders));
        }
Example #18
0
        public async Task <OrderDto> CreateOrderAsync(OrderDto order)
        {
            Models.Orders newOrder = this._mapper.Map <Models.Orders>(order);
            await this._dbContext.Orders.AddAsync(newOrder);

            await this._dbContext.SaveChangesAsync();

            return(order);
        }
Example #19
0
        public IHttpActionResult GetOrders(string id)
        {
            Models.Orders orders = db.Orders.Find(id);
            if (orders == null)
            {
                return(NotFound());
            }

            return(Ok(orders));
        }
Example #20
0
        // GET: Orders
        public ActionResult Index(Models.Orders selectitem)
        {
            ViewBag.data = ordersService.GetOrdersById(selectitem);

            ViewBag.CompanyName     = this.codeService.GetCustomer();
            ViewBag.empData         = this.codeService.GetEmpname();
            ViewBag.shipData        = this.codeService.GetShipperName();
            ViewBag.ProductCodeData = this.codeService.GetProduct();
            return(View(new Models.Orders()));
        }
        public ActionResult Edit(Models.Orders order)
        {
            Models.NorthwindEntities db = new Models.NorthwindEntities();
            //var _order = db.Orders.First(o => o.OrderID == order.OrderID);
            db.Set <Models.Orders>().AsNoTracking().FirstOrDefault(o => o.OrderID == order.OrderID);

            db.Entry(order).State = EntityState.Modified;
            db.SaveChanges();
            return(View());
        }
Example #22
0
 public Entities.Orders ParseOrders(Models.Orders orders)
 {
     return(new Entities.Orders()
     {
         Date = orders.OrderDate,
         Cost = (int)orders.Cost,
         Customerid = orders.CustomerId,
         Locationid = orders.LocationId,
         Id = orders.Id
     });
 }
Example #23
0
        public IHttpActionResult DeleteOrders(string id)
        {
            Models.Orders orders = db.Orders.Find(id);
            if (orders == null)
            {
                return(NotFound());
            }

            db.Orders.Remove(orders);
            db.SaveChanges();

            return(Ok(orders));
        }
Example #24
0
 public JsonResult GetOrders(string id)
 {
     Models.Orders odrs = null;
     try
     {
         odrs = _mapper.Map <Models.Orders>(repository.GetOrderById(id));
     }
     catch (Exception ex)
     {
         odrs = null;
     }
     return(new JsonResult(odrs));
 }
Example #25
0
        public ActionResult Index(Models.OrderModel.Ship postback)
        {
            if (this.ModelState.IsValid)
            {
                //取得目前購物車
                var currentcart = Models.Carts.Operation.GetCurrentCart();

                using (Models.SmartShoppingEntities ss = new Models.SmartShoppingEntities())
                {
                    //取得目前登入使用者Id
                    if (User.Identity.IsAuthenticated)
                    {
                        string aspid = User.Identity.GetUserId();
                        MemberID = ss.Members.Where(m => m.Id == aspid).Select(m => m.Member_ID).First();
                    }


                    //建立 Order 物件
                    int T     = (int)currentcart.TotalAmount;
                    var order = new Models.Orders()
                    {
                        //Order_ID
                        Member_ID        = MemberID,
                        OrderDate        = DateTime.Now,
                        SubTotal         = T,
                        ValueAddTax      = System.Convert.ToInt32(T * 0.05),
                        ShippingFee      = 50,
                        Amount           = System.Convert.ToInt32(T * 1.05 + 50),
                        Consignee        = postback.Consignee,
                        ShipAddress      = postback.ShipAddress,
                        ShipMethod_ID    = 1,
                        PaymentMethod_ID = 1,
                        Status_ID        = 2,
                        Comment          = postback.ConsigneePhone
                    };

                    //將其加入 Orders資料表後,儲存變更
                    ss.Orders.Add(order);
                    ss.SaveChanges();

                    //取得購物車中OrderDetail物件
                    var orderDetails = currentcart.ToOrderDetailList(order.Order_ID);

                    //將其加入 OrderDetails 資料表後,儲存變更
                    ss.OrderDetail.AddRange(orderDetails);
                    ss.SaveChanges();
                }
                return(Content("訂購成功,感謝您訂購我們的產品  <a href='Home/Index'>回首頁</a>"));
            }
            return(View());
        }
Example #26
0
        public JsonResult UpdateOrder(Models.Orders odr)
        {
            bool status = false;

            try
            {
                status = repository.UpdateOrder(_mapper.Map <Orders>(odr));
            }
            catch (Exception ex)
            {
                status = false;
            }
            return(new JsonResult(status));
        }
Example #27
0
        // GET: Order/Details/5
        public ActionResult Details(int id)
        {
            var order = db.GetOrdersByOrderId(id);

            c = new Models.Orders();

            c.OrderId      = order.OrderId;
            c.RestaurantId = order.RestaurantId;
            c.CustomerId   = order.CustomerId;
            c.TotalCost    = order.TotalCost;
            c.OrderDate    = order.OrderDate;
            ordersList.Add(c);

            return(View(c));
        }
Example #28
0
        public List<Models.Orders> GetOrders(string path)
        {
            List<Models.Orders> orders = new List<Models.Orders>();

            try
            {
                string[] data = File.ReadAllLines(path);
                for (int i = 1; i < data.Length; i++)
                {
                    string[] row = data[i].Split(',');

                    Models.Orders toAdd = new Models.Orders();
                    toAdd.OrderNumber = int.Parse(row[0]);
                    toAdd.CustomerName = row[1];
                    toAdd.State = row[2];
                    toAdd.TaxRate = decimal.Parse(row[3]);
                    toAdd.ProductType = row[4];
                    toAdd.Area = decimal.Parse(row[5]);
                    toAdd.CostPerSquareFoot = decimal.Parse(row[6]);
                    toAdd.LaborCostPerSquareFoot = decimal.Parse(row[7]);
                    toAdd.MaterialCost = decimal.Parse(row[8]);
                    toAdd.LaborCost = decimal.Parse(row[9]);
                    toAdd.Tax = decimal.Parse(row[10]);
                    toAdd.Total = decimal.Parse(row[11]);

                    orders.Add(toAdd);
                }
            }
            catch
            {
                ArgumentException ex = new ArgumentException("File is corrupt. Could not load.");
                Console.Write(ex.Message);
                Console.WriteLine(" You must choose another date.\n Press enter to continue");
                Console.ReadLine();
                Console.Clear();
                string directory = @"Data\Error.txt";
                if (!File.Exists(directory))
                    File.CreateText(directory).Close();
                using (StreamWriter writer = new StreamWriter(directory, true))
                {
                    writer.WriteLine(ex + "\n" + DateTime.Now); //Message + "\n" + ex.StackTrace);
                }
                throw ex;
            }

            return orders;
        }
Example #29
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Orders = await _context.Orders.FindAsync(id);

            if (Orders != null)
            {
                _context.Orders.Remove(Orders);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Example #30
0
        private async void buttonAddOrder_Click(object sender, System.EventArgs e)
        {
            if (!VerifyOrdersValues(out var summ, out var payment))
            {
                return;
            }
            if (selectedClientsRow[0] == null)
            {
                return;
            }
            var selectedClientRow = selectedClientsRow[0];
            var workers           = await _workerRepository.GetWorkersWhoRole("archivarius");

            foreach (var worker in workers)
            {
                if (worker.Orders != null)
                {
                    if (worker.Orders.Count < buff)
                    {
                        buff            = worker.Orders.Count;
                        _chosenWorkerId = worker.Id;
                    }
                }
                else
                {
                    buff            = 0;
                    _chosenWorkerId = worker.Id;
                }
            }

            var order = new Models.Orders()
            {
                ClientId      = Convert.ToInt32(selectedClientRow.Cells[0].Value),
                Payment       = Convert.ToInt32(summ),
                PaymentIsDone = Convert.ToInt32(payment),
                TimeCreated   = DateTime.Now,
                WorkerId      = _chosenWorkerId
            };

            NormalizeTables();
            await _ordersRepository.CreateOrder(order);

            await UpdateDataGridViewOrders(Convert.ToInt32(textBoxIdClient.Text));
        }
Example #31
0
        public IActionResult CheckOut([Bind("FirstName,LastName,Address,City,Province,postalCode")] Models.Orders orders)
        {
            //Order Properties
            orders.OrderDate  = DateTime.Now;
            orders.CustomerId = User.Identity.Name;
            //calculation total in cart
            orders.Total = (from c in _context.Cart
                            where c.CustomerId == HttpContext.Session.GetString("CustomerId")
                            select c.Quantity *c.TotalPrice).Sum();



            //use sessionextension obj to store the order obj in asession variable
            HttpContext.Session.SetObject("Orders", orders);


            //redirect to payment page
            return(RedirectToAction("Payment"));
        }