public async Task <IHttpActionResult> DeleteOrderline(int id)
        {
            Orderline orderline = await db.Orderlines.FindAsync(id);

            if (orderline == null)
            {
                return(NotFound());
            }

            db.Orderlines.Remove(orderline);
            await db.SaveChangesAsync();

            return(Ok(orderline));
        }
示例#2
0
        // GET: Orderlines/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Orderline orderline = db.Orderlines.Find(id);

            if (orderline == null)
            {
                return(HttpNotFound());
            }
            return(View(orderline));
        }
示例#3
0
        public IActionResult Create([Bind("ProductId,OrderId,Quantity")] Orderline orderline)
        {
            var lastOrderPlaced = ordsDAL.preOrder();

            orderline.OrderId = lastOrderPlaced.OrderId;
            if (ModelState.IsValid)
            {
                _context.Orderline.Add(orderline);
                _context.SaveChanges();
                return(RedirectToAction(nameof(Create)));
            }
            ViewData["Quantity"]  = new SelectList(_context.Orders, "Quantity", "Quantity", orderline.OrderId);
            ViewData["ProductId"] = new SelectList(_context.Games, "ProductId", "Title", orderline.ProductId);
            return(View(orderline));
        }
        public async Task <Orderline> Create(Orderline orderline)
        {
            if (orderline == null)
            {
                throw new Exception();
            }
            await _context.Orderlines.AddAsync(orderline);

            await _context.SaveChangesAsync();

            Refresh(orderline);
            await CalculateOrderTotal(orderline.OrderId);

            return(orderline);
        }
示例#5
0
        // GET: Orderlines/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Orderline orderline = db.Orderlines.Find(id);

            if (orderline == null)
            {
                return(HttpNotFound());
            }
            ViewBag.OrderId = new SelectList(db.Orders, "Id", "Description", orderline.OrderId);
            return(View(orderline));
        }
示例#6
0
        static async Task TestOrderlines()
        {
            var lineCtrl  = new OrderlinesController();
            var orderline = new Orderline()
            {
                Id = 1, OrderId = 1, ProductId = 1, Quantity = 1
            };
            await lineCtrl.Change(orderline.Id, orderline);

            orderline = new Orderline()
            {
                Id = 0, OrderId = 1, ProductId = 3, Quantity = 3
            };
            //await lineCtrl.Create(orderline);
        }
示例#7
0
        private void SaveButtong_Click(object sender, RoutedEventArgs e)
        {
            Order order = new Order();

            //var orderuser =App.userService.GetActiveUsers().FirstOrDefault(p => p.ID.Equals(selecteduser.User.ID));

            order.UserId = selecteduser.User.ID;

            orderlines.Where(o => o.Amount > 0).ToList().ForEach(o =>
            {
                if (o.Amount > 0)
                {
                    Orderline orderline = o.GetOrderLine(order);
                    order.Orderlines.Add(orderline);
                }
            });
            App.orderService.SaveOrders(order);

            var xmlToastTemplate = "<toast launch=\"app-defined-string\">" +
                                   "<visual>" +
                                   "<binding template =\"ToastGeneric\">" +
                                   "<text>Order Saved!</text>" +
                                   "<text>" +
                                   string.Format("Order {0} is saved for {1}", order.ID.ToString(), selecteduser.User.Name) +
                                   "</text>" +
                                   "</binding>" +
                                   "</visual>" +
                                   "</toast>";

            // load the template as XML document
            var xmlDocument = new Windows.Data.Xml.Dom.XmlDocument();

            xmlDocument.LoadXml(xmlToastTemplate);

            // create the toast notification and show to user
            var toastNotification = new ToastNotification(xmlDocument);

            toastNotification.Tag            = "OrderSaved";
            toastNotification.Group          = "BiesterlanOrders";
            toastNotification.ExpirationTime = DateTime.Now.AddSeconds(3);
            var notification = ToastNotificationManager.CreateToastNotifier();

            notification.Show(toastNotification);



            On_BackRequested();
        }
        // GET: Orderlines/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Orderline orderline = db.Orderlines.Find(id);

            if (orderline == null)
            {
                return(HttpNotFound());
            }
            ViewBag.OrderID   = new SelectList(db.Orders, "OrderID", "CustomerID", orderline.OrderID);
            ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductDescription", orderline.ProductID);
            return(View(orderline));
        }
示例#9
0
        static void AddOrderline(AppDbContext context)
        {
            var order     = context.Orders.SingleOrDefault(o => o.Description == "Frying Pan");
            var product   = context.Products.SingleOrDefault(p => p.Code == "BRVC");
            var orderline = new Orderline {
                ID = 0, ProductID = product.ID, OrderID = order.ID, Quantity = 5
            };

            context.Orderlines.Add(orderline);
            var rowsAffected = context.SaveChanges();

            if (rowsAffected != 1)
            {
                throw new Exception("Ordeline Insert Failed");
            }
        }
示例#10
0
        public List <Orderline> getOrderlines(int id)
        {
            if (id == 0)
            {
                return(null);
            }
            else
            {
                var expected_result = new List <Orderline>();

                var orderline = new Orderline()
                {
                    Id      = 1,
                    Antall  = 1,
                    MovieId = 1,
                    OrderId = 1,
                    Movie   = new Movie()
                    {
                        Id           = 1,
                        ImageAddress = "/Images/avengers.jpg",
                        Title        = "Avengers",
                        Description  = "Lalala",
                        Price        = 50,
                        Genre        = "action"
                    },
                    Order = new Order()
                    {
                        Id        = 1,
                        Confirmed = true,
                        SessionId = "hgfvjegvfjegvf",
                        Customer  = new Customer()
                        {
                            Id       = 1,
                            Name     = "Iryna",
                            Surname  = "Martynchuk",
                            Email    = "*****@*****.**",
                            Password = "******"
                        }
                    }
                };

                expected_result.Add(orderline);
                expected_result.Add(orderline);
                expected_result.Add(orderline);
                return(expected_result);
            }
        }
示例#11
0
        public ActionResult CreateOrderline(Orderline orderline)
        {
            if (!LoggedIn())
            {
                return(RedirectToAction("LogIn"));
            }

            if (ModelState.IsValid)
            {
                var order = (Order)Session["Order"];

                if (order != null)
                {
                    orderline.orderID = order.id;
                    Session["Order"]  = null;

                    // validering på produktID - om et produkt med denne id'en finnes:
                    var product = dbBLL.GetProduct(orderline.productId);

                    if (product != null)
                    {
                        Session["ErrorMessageOrderline"] = null;

                        bool insertOK = dbBLL.CreateOrderline(orderline);

                        var userId = (int)Session["UserIdForOrders"];

                        if (insertOK)
                        {
                            return(RedirectToAction("AdminOrders", new { id = userId }));
                        }
                    }
                    else
                    {
                        // Submit-knappen fungerer ikke lenger når vi bare tar return View() etter å ha fått feilen
                        // at produkt-id ikke finnes. Derfor:

                        //ModelState.AddModelError("", "Produkt med produkt id " + orderline.productId + " finnes ikke!");
                        Session["ErrorMessageOrderline"] = "Produkt med produkt id " + orderline.productId + " finnes ikke!";
                        return(RedirectToAction("CreateOrderline", new { id = order.id }));
                        // og så tester jeg på Session-variabelen i CreateOrderline(int id)
                    }
                }
            }

            return(View());
        }
示例#12
0
        public bool deleteCartItem(int id)
        {
            var       db        = new DBContext();
            Orderline orderline = db.Orderlines.First(x => x.MovieId == id);

            try
            {
                db.Orderlines.Remove(orderline);
                db.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                Error.logError("Order:deleteCartItem", e);
                return(false);
            }
        }
示例#13
0
        //public BitmapImage GetBitMapSource
        //{
        //    get
        //    {
        //        Image img = new Image();
        //        BitmapImage bitmapImage = new BitmapImage();
        //        Uri uri = new Uri(string.Format("file:///{0}", this.Article.ImagePath));
        //        bitmapImage.UriSource = uri;
        //        return bitmapImage;
        //    }

        //}

        public Orderline GetOrderLine(Order order)
        {
            if (Amount == 0)
            {
                return(null);
            }
            else
            {
                Orderline orderline = new Orderline();
                orderline.ArticleID  = Article.ID;
                orderline.Name       = Article.Name;
                orderline.Amount     = Amount;
                orderline.SalesPrice = Article.SalesPrice;
                orderline.Order      = order;
                return(orderline);
            }
        }
        public async Task Change(int id, Orderline orderline)
        {
            if (orderline == null)
            {
                throw new Exception("Orderline cannot be null");
            }
            if (id != orderline.Id)
            {
                throw new Exception("Orderline not found");
            }

            _context.Entry(orderline).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            Refresh(orderline);
            await CalculateOrderTotal(orderline.OrderId);
        }
示例#15
0
        // Helping method used to convert OrderRefernce.Orderline to Client.Domain.Orderline
        private Orderline BuildClientOrderline(OrderReference.OrderLine orderline)
        {
            Orderline ol = new Orderline();

            if (orderline.Product != null)
            {
                Product p = new Product();
                p.ID       = orderline.Product.ID;
                p.Stock    = orderline.Product.Stock;
                p.Price    = orderline.Product.Price;
                ol.Product = p;
            }
            ol.ID           = orderline.ID;
            ol.Quantity     = orderline.Quantity;
            ol.SubTotal     = orderline.SubTotal;
            ol.ErrorMessage = orderline.ErrorMessage;
            return(ol);
        }
示例#16
0
        public async Task <Orderline> Create(Orderline orderline)
        {
            if (orderline == null)
            {
                throw new Exception("Input cannot be null");
            }
            if (orderline.Id != 0)
            {
                throw new Exception("Input must have Id set to zero");
            }
            _context.Orderlines.Add(orderline);
            var rowsAffected = await _context.SaveChangesAsync();

            if (rowsAffected != 1)
            {
                throw new Exception("Create failed!");
            }
            return(orderline);
        }
示例#17
0
        public async Task <Orderline> Create(Orderline orderline)
        {
            if (orderline == null)
            {
                throw new Exception("Orderline cannot be null");
            }
            if (orderline.Id != 0)
            {
                throw new Exception("Item Id must be zero");
            }
            _context.orderlines.Add(orderline);
            var rowsAffect = await _context.SaveChangesAsync();// it's important to remember to do SaveChanges

            if (rowsAffect != 1)
            {
                throw new Exception("Create failed!");
            }
            return(orderline);
        }
示例#18
0
        //public async Task<Item> Create(Orderline orderline)
        //{
        //    if (orderline == null)
        //    {
        //        throw new Exception("Order cannot be NULL");
        //    }
        //    if (orderline.Id != 0)
        //    {
        //        throw new Exception("Order ID must be ZERO");
        //    }
        //    await _context.Orderlines.AddAsync(orderline);
        //    var rowsaffected = await _context.SaveChangesAsync();
        //    if (rowsaffected != 1)
        //    {
        //        throw new Exception("Create FAILED!!!");
        //    }
        //    return orderline;
        //}

        public async Task Change(Orderline orderline)
        {
            if (orderline == null)
            {
                throw new Exception("Order cannot be NULL");
            }
            if (orderline.Id < 0)
            {
                throw new Exception("Order ID must be greater then ZERO");
            }
            _context.Entry(orderline).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            var rowsaffected = await _context.SaveChangesAsync();

            if (rowsaffected != 1)
            {
                throw new Exception("Change FAILED!!!");
            }
            return;
        }
        public async Task <ActionResult <Orderline> > DeleteOrderline(Orderline orderline)
        {
            var cmd = _context.Database.GetDbConnection().CreateCommand();

            cmd.CommandText = "REMOVE_PRODUCT_FROM_ORDER";

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("PORDERID", orderline.Orderid));
            cmd.Parameters.Add(new SqlParameter("PPRODIID", orderline.Productid));

            await cmd.Connection.OpenAsync();

            await cmd.ExecuteNonQueryAsync();

            await cmd.Connection.CloseAsync();

            return(Ok());
        }
        private void Ordre_Opdater_Tilføj_Ordrelinje_Knap_Click(object sender, RoutedEventArgs e)
        {
            try {
                Product p = new Product();
                if (Int32.TryParse(Ordre_Opdater_ProductName_TextBox.Text, out int i))
                {
                    p = productController.GetProduct("productID", i.ToString());
                    if (p.ErrorMessage == "")
                    {
                        Ordre_Opdater_Label_Tilføjet.Content = p.ErrorMessage;
                    }
                }
                else
                {
                    p = productController.GetProduct("name", Ordre_Opdater_ProductName_TextBox.Text);
                    if (p.ErrorMessage == "")
                    {
                        Ordre_Opdater_Label_Tilføjet.Content = p.ErrorMessage;
                    }
                }
                int       quantity  = Int32.Parse(Ordre_Opdater_Antal_TextBox.Text);
                decimal   subTotal  = p.Price * quantity;
                int       orderID   = Int32.Parse(Ordre_Opdater_Find_Ordre_TextBox.Text);
                Orderline orderline = orderController.CreateOrderLineInDesktop(quantity, subTotal, p.ID, orderID);

                if (orderline.ErrorMessage == "")
                {
                    Ordre_Opdater_Label_Tilføjet.Content = "Ordrelinjen blev oprettet";
                    CreateOrderlineHandler();
                    ClearOrderLineFields();
                }
                else
                {
                    Ordre_Opdater_Label_Tilføjet.Content = orderline.ErrorMessage;
                }
            }
            catch (FormatException) {
                MessageBox.Show("Ugyldig tekst indsat");
            }
            catch (OverflowException) {
                MessageBox.Show("Du har indtastet for store tal værdier");
            }
        }
示例#21
0
        public async Task Change(Orderline orderline)
        {
            if (orderline == null)
            {
                throw new Exception("Input cannot be null");
            }
            if (orderline.Id == 0)
            {
                throw new Exception("Input must have Id greater than zero");
            }
            _context.Entry(orderline).State = EntityState.Modified;
            var rowsAffected = await _context.SaveChangesAsync();

            if (rowsAffected != 1)
            {
                throw new Exception("Change failed!");
            }
            return;
        }
示例#22
0
        //below are orderline table stuff
        static void AddOrderline(AppDbContext context)
        {
            var order     = context.Orders.SingleOrDefault(o => o.Description == "Order 5");
            var product   = context.Products.SingleOrDefault(p => p.Code == "prod2");
            var orderline = new Orderline {
                Id        = 0,
                ProductId = product.Id,
                OrderId   = order.Id,
                Quantity  = 1
            };

            context.Orderlines.Add(orderline);
            var rowsAffected = context.SaveChanges();

            if (rowsAffected != 1)
            {
                throw new Exception("Orderline insert failed!");
            }
        }
示例#23
0
        // Gets orderlne and builds Client.Domain.Product
        public Orderline FindOrderLine(int id)
        {
            var       ol        = myProxy.FindOrderLine(id);
            Orderline orderline = new Orderline();

            if (ol != null)
            {
                Product p = new Product {
                    ID = ol.Product.ID
                };

                orderline.ID       = ol.ID;
                orderline.Quantity = ol.Quantity;
                orderline.SubTotal = ol.SubTotal;
                orderline.Product  = p;
            }

            return(orderline);
        }
示例#24
0
        public async Task <Orderline> Change(Orderline orderline)
        {
            if (orderline == null)
            {
                throw new Exception("Item cannot be null");
            }
            if (orderline.Id <= 0)
            {
                throw new Exception("Id must be greater than zero");
            }
            _context.Entry(orderline).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            var rowsAffect = await _context.SaveChangesAsync();

            if (rowsAffect != 1)
            {
                throw new Exception("Changed failed");
            }
            return(orderline);
        }
示例#25
0
        public IActionResult Einde()
        {
            //check eerst dat alle items in Winkelmand nog bestaan in ShopItems
            //zonder check krijg je later bij .SaveChanges() een SQL/DB-error:
            //indien items in winkelmand ligt
            //en item wordt verwijderd uit productbeheer
            //en dan wordt order geplaatst -> SQL/DB-error
            //want ShopItem bestaat niet meer

            foreach (var item in _database.Winkelmandje)
            {
                var databaseitem = _databaseContext.ShopItems.SingleOrDefault(a => a.Id == item.Id);
                if (databaseitem == null)
                {
                    Console.Write("Onbekend item in winkelmand!");
                    _database.Winkelmandje.Clear();
                    return(RedirectToAction("Index"));
                }
            }

            //Indien alle items winkelmand bestaan in In-memory database-ShopItems
            //wordt order gemaakt
            Order order = new Order();

            _databaseContext.Add(order);
            _databaseContext.SaveChanges();

            //orderlines maken van winkelmand-items voor dit order
            foreach (var item in _database.Winkelmandje)
            {
                Orderline orderline = new Orderline()
                {
                    OrderId    = order.Id,
                    ShopItemId = item.Id
                };

                _databaseContext.Orderlines.Add(orderline);
                _databaseContext.SaveChanges();
            }

            return(View());
        }
示例#26
0
        public List <Order> GetOrdersForUser(int userId)
        {
            using (var db = new DBContext())
            {
                try
                {
                    var          dbOrders    = db.Orders.ToList();
                    List <Order> outputOrder = new List <Order>();
                    foreach (var order in dbOrders)
                    {
                        if (order.UserID == userId)
                        {
                            var oneOrder = new Order();
                            oneOrder.id         = order.ID;
                            oneOrder.userID     = order.UserID;
                            oneOrder.date       = order.Date;
                            oneOrder.orderlines = new List <Orderline>();

                            foreach (var orderline in order.Orderlines)
                            {
                                var NewOrderLine = new Orderline();
                                NewOrderLine.productId = orderline.ProductID;
                                NewOrderLine.quantity  = orderline.Quantity;
                                NewOrderLine.orderID   = oneOrder.id;
                                oneOrder.orderlines.Add(NewOrderLine);
                            }
                            outputOrder.Add(oneOrder);
                        }
                    }

                    return(outputOrder);
                }
                catch (Exception)
                {
                    var output     = new List <Order>();
                    var errorOrder = new Order();
                    errorOrder.id = 1337;
                    output.Add(errorOrder);
                    return(output);
                }
            }
        }
        private void addOrderlineButton_Click(object sender, RoutedEventArgs e)
        {
            try {
                Product p = new Product();
                if (Int32.TryParse(Ordre_Opret_Find_Product_TextBox.Text, out int i))
                {
                    p = productController.GetProduct("productID", i.ToString());
                    if (p.ErrorMessage != "")
                    {
                        Ordre_Opret_Tilføjet_Label.Content = p.ErrorMessage;
                    }
                }
                else
                {
                    p = productController.GetProduct("name", Ordre_Opret_Find_Product_TextBox.Text);
                    if (p.ErrorMessage != "")
                    {
                        Ordre_Opret_Tilføjet_Label.Content = p.ErrorMessage;
                    }
                }
                int       quantity = Int32.Parse(Ordre_Opret_Antal_TextBox.Text);
                decimal   subTotal = p.Price * quantity;
                Orderline ol       = orderController.CreateOrderLine(quantity, subTotal, p.ID);

                if (ol.ErrorMessage == "")
                {
                    orderlines.Add(ol);
                    Ordre_Opret_Tilføjet_Label.Content = "Ordrelinjen blev oprettet";
                    OrdrelineClearFields();
                }
                else
                {
                    Ordre_Opret_Tilføjet_Label.Content = ol.ErrorMessage;
                }
            }
            catch (FormatException) {
                MessageBox.Show("Ugyldig tekst indsat");
            }
            catch (OverflowException) {
                MessageBox.Show("Du har indtastet for store tal værdier");
            }
        }
示例#28
0
 public Orderline GetOrderline(int id)
 {
     if (id == 0)
     {
         var orderLine = new Orderline();
         orderLine.id = 0;
         return(orderLine);
     }
     else
     {
         var orderLine = new Orderline()
         {
             id        = 1,
             orderID   = 1,
             productId = 1,
             quantity  = 1
         };
         return(orderLine);
     }
 }
示例#29
0
        public IActionResult Create([Bind("LocationId,CustomerId,ProductID")] OrdersViewModel ordersV)
        {
            Game_RealmContext ctx = new Game_RealmContext();

            if (ModelState.IsValid)
            {
                string orderlinesController = "Orderlines";
                Orders newOrd = new Orders
                {
                    CustomerId = ordersV.CustomerId,
                    StoreId    = ordersV.LocationId,
                    Time       = DateTime.Now,
                    Checkout   = 0
                };



                _context.Add(newOrd);
                _context.SaveChanges();
                _context.Entry(newOrd).Reload();
                Orderline ords = new Orderline
                {
                    OrderId   = newOrd.OrderId,
                    ProductId = ordersV.ProductID,
                    Quantity  = 1,
                };

                _context.Orderline.Add(ords);
                _context.SaveChanges();
                _context.Entry(ords).Reload();
                return(RedirectToAction(nameof(Create), orderlinesController));
            }



            ViewData["CustomerId"] = new SelectList(_context.Customer, "CustomerId", "FirstName");
            ViewData["StoreId"]    = new SelectList(_context.Locations, "StoreId", "StoreName");
            ViewData["ProductID"]  = new SelectList(_context.Games, "ProductId", "Title");
            ViewData["Price"]      = new SelectList(_context.Games, "Price", "Price");
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <ActionResult <Orderline> > PostOrderline(Orderline orderline)
        {
            var cmd = _context.Database.GetDbConnection().CreateCommand();

            cmd.CommandText = "ADD_PRODUCT_TO_ORDER";

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add(new SqlParameter("PORDERID", orderline.Orderid));
            cmd.Parameters.Add(new SqlParameter("PPRODIID", orderline.Productid));
            cmd.Parameters.Add(new SqlParameter("PQTY", orderline.Quantity));
            cmd.Parameters.Add(new SqlParameter("DISCOUNT", orderline.Discount));

            await cmd.Connection.OpenAsync();

            await cmd.ExecuteNonQueryAsync();

            await cmd.Connection.CloseAsync();

            return(Ok());
        }