public T Save(T entity)
 {
     entity.GenerateId();
     _context.Add(entity);
     _context.SaveChanges();
     return(entity);
 }
        private void Seed()
        {
            using (var context = new OrderContext(ContextOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                var orderItemOne = new OrderItem
                {
                    ProductType = ProductType.PhotoBook,
                    Quantity    = 1
                };

                var orderItemTwo = new OrderItem
                {
                    ProductType = ProductType.Mug,
                    Quantity    = 3
                };

                var orderOne = new Order
                {
                    OrderID    = 1,
                    OrderItems = new List <OrderItem>
                    {
                        orderItemOne,
                        orderItemTwo
                    }
                };

                context.Add(orderOne);
                context.SaveChanges();
            }
        }
        public IActionResult MakeOrder(string name)
        {
            var basket = shbasket.basket.ToList();

            foreach (var item in basket)
            {
                if (item.Email == name)
                {
                    if (item.isSent != "+")
                    {
                        item.isSent = "+";
                        OrderViewModel order = new OrderViewModel
                        {
                            Name        = item.Name,
                            Count       = item.Count,
                            Email       = item.Email,
                            Id          = item.Id,
                            PhoneNumber = item.PhoneNumber,
                            Price       = item.Price,
                            ProductName = item.ProductName,
                            unit        = item.unit
                        };
                        db.Add(order);
                        db.SaveChanges();
                        SendMessage(order).Wait();
                        shbasket.Update(item);
                        shbasket.SaveChanges();
                    }
                }
            }
            return(RedirectToAction("MyOrders"));
        }
Esempio n. 4
0
 public void AddItem(Order order, Item item)
 {
     order.OrderItems.Add(item);
     _context.Add(item);
     _context.Update(order);
     _context.SaveChanges();
 }
        public void Test_GetStoreOrders()
        {
            var options = new DbContextOptionsBuilder <OrderContext>()
                          .UseInMemoryDatabase(databaseName: "TestDb6")
                          .Options;

            AStore store     = new AStore();
            Order  testOrder = new Order();

            testOrder.Store          = store.StoreID;
            testOrder.JSONPizzaOrder = "teststring";
            using (var context = new OrderContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                context.Add <Order>(testOrder);
                context.SaveChanges();
            }

            using (var context = new OrderContext(options))
            {
                OrderRepository orderRepo = new OrderRepository(context);

                List <Order> getOrders = orderRepo.GetStoreOrders(store.StoreID);

                Assert.Equal(testOrder.JSONPizzaOrder, getOrders[0].JSONPizzaOrder);
            }
        }
 public override string Execute(List <string> parameters)
 {
     if (parameters.Count != 3)
     {
         return(ErrorType.PARAMETER_IS_NOT_SUFFICIENT.ToString());
     }
     try
     {
         string         productCode    = parameters[1];
         double         quantity       = double.Parse(parameters[2]);
         ProductContext productContext = new ProductContext();
         Product        product        = productContext.Get(productCode);
         if (product == null)
         {
             return(ErrorType.PRODUCT_NOT_FOUND.ToString());
         }
         if (product.GetStock() < quantity)
         {
             return(ErrorType.PRODUCT_STOCK_IS_NOT_SUFFICIENT.ToString());
         }
         product.DecreaseStock(quantity);
         CampaignContext campaignContext = new CampaignContext();
         var             response        = campaignContext.PriceByProduct(product);
         Order           order           = new Order(productCode, response.Item1, quantity, response.Item2);
         OrderContext    orderContext    = new OrderContext();
         orderContext.Add(order);
         return($"Order created; product {productCode}, quantity {quantity}");
     }
     catch (System.Exception)
     {
         return(ErrorType.UNKNOWN_EXCEPTION.ToString());
     }
 }
Esempio n. 7
0
        public async Task <IActionResult> Create([Bind("Id,AmountPizza,User_idUser,Pizza_IdPizza,User_Location_IdLocation,DateOrder")] Orders orders)
        {
            var pizzaAm = int.Parse(orders.AmountPizza.ToString());

            if (pizzaAm > 12)
            {
                return(NotFound());
            }
            else
            {
                if (ModelState.IsValid)
                {
                    var pizzaOb = int.Parse((from pizza in _context.Pizza where pizza.Id == orders.Pizza_IdPizza select pizza.PiizaCount).ToList().FirstOrDefault().ToString());
                    var author  = _context.Pizza.First(a => a.Id == orders.Pizza_IdPizza);
                    var total   = pizzaOb - pizzaAm;
                    author.PiizaCount = total;
                    await _context.SaveChangesAsync();

                    _context.Add(orders);
                    await _context.SaveChangesAsync();



                    return(RedirectToAction(nameof(Index)));
                }
                return(View(orders));
            }
        }
Esempio n. 8
0
        public RedirectResult  Post(Donate donate)
        {
            order = new Order();
            if (ModelState.IsValid && donate != null)
            {
                order.Amount       = donate.amountOfDonation;
                order.Descriptioin = donate.Comment;
                order.Number       = Guid.NewGuid().ToString();
                order.Id           = Guid.NewGuid().ToString();
                string resultOrderResponse = helper.RegisterOrder(order).Result;

                dynamic parsejsonString = JObject.Parse(resultOrderResponse);


                string formUrl   = parsejsonString.formUrl;
                int    errorCode = parsejsonString.errorCode;


                if (errorCode == 0)
                {
                    _context.Add(order);
                    _context.SaveChanges();
                    return(Redirect(formUrl));
                }
                else
                {
                    return(Redirect("/Home"));
                }
            }
            else
            {
                var response = new HttpResponseMessage(HttpStatusCode.BadRequest);
                return(Redirect("/Home"));
            }
        }
Esempio n. 9
0
        private bool SaveOrder(Order order)
        {
            if (!ModelState.IsValid)
            {
                return(false);
            }
            var addressId   = SaveAddressAsync(order.Address).Result;
            var orderDb     = new OrderDB();
            var orderDbItem = _orderContext.Orders.FirstOrDefault();

            if (orderDbItem == null)
            {
                orderDb.Id = 1;
            }
            else
            {
                var orderId = _orderContext.Orders.Max(x => x.Id);
                orderId++;
                orderDb.Id = orderId;
            }
            orderDb.Status      = 0;
            orderDb.Description = order.Description;
            orderDb.AddressId   = addressId;
            List <OrderDbItem> productDbList = new List <OrderDbItem>();

            order.Items.ForEach(x => productDbList.Add(OrderDbItem.ConvertProduct(x.Product, x.Count)));
            orderDb.Items = JsonConvert.SerializeObject(productDbList);
            _orderContext.Add(orderDb);
            _orderContext.SaveChanges();

            // SaveOrderInformation()
            return(true);
        }
Esempio n. 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="customer"></param>
        public Customer AddCustomerIfNotExists(Customer customer)
        {
            Customer customerDTO = new Customer();

            using (var orderContext = new OrderContext())
            {
                var customerRecord = orderContext.customers.Where(c => c.UserName == customer.UserName).FirstOrDefault();
                if (customerRecord != null)
                {
                    customerDTO = new Customer {
                        UserName = customer.UserName, PhoneNumber = customer.PhoneNumber, Address = customer.Address, Amount = customer.Amount
                    };
                    orderContext.Update(customerDTO);
                }
                else
                {
                    customerDTO = new Customer {
                        CustomerId = customer.CustomerId, UserName = customer.UserName, PhoneNumber = customer.PhoneNumber, Address = customer.Address, Amount = customer.Amount
                    };
                    orderContext.Add(customerDTO);
                }
                orderContext.SaveChanges();
            }
            return(customerDTO);
        }
        public async Task <T> AddAsync(T entity)
        {
            _dbContext.Add(entity);
            await _dbContext.SaveChangesAsync();

            return(entity);
        }
Esempio n. 12
0
        public async Task <ActionResult <Order> > PostOrder([FromBody] Order order)
        {
            _context.Add(order);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       nameof(PostOrder),
                       new { Id = order.Id },
                       order));
        }
        public async Task <IActionResult> Create([Bind("OrderNumber,CustomerName,ShippingAddress,BillingAddress,ItemName,PurchasedQty,ItemPrice")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(order));
        }
Esempio n. 14
0
        public async Task <IActionResult> Create([Bind("Id,AllPrice,Time")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(order));
        }
        public async Task <IActionResult> Create([Bind("CustomerId,CustomerName,Email,MobileNo")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Esempio n. 16
0
        public async Task <IActionResult> Create([Bind("Id,RestaurantName,Street,City,State,Zip")] TblRestaurants tblRestaurants)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tblRestaurants);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tblRestaurants));
        }
Esempio n. 17
0
        public async Task <IActionResult> Create([Bind("ID,Name,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Esempio n. 18
0
        public async Task <IActionResult> Create([Bind("ItemId,PlanSeqId,ItemDescription,OrderQuantity,OrderSldTdy,PlannedMinutesQty,ActualMinutesQty,NetworkId,CompanyId,AvaiForSaleQty,ShowDate,ShowCd")] USA uSA)
        {
            if (ModelState.IsValid)
            {
                _context.Add(uSA);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(uSA));
        }
Esempio n. 19
0
        public async Task <IActionResult> Create([Bind("OrderId,UserId,Total,Date,TempId,Shipping,Address,Zip,City")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(order));
        }
Esempio n. 20
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Address,Street,City,Country,Email,PhoneNumber,Date,Done,Amount")] OrderModel orderModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orderModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(orderModel));
        }
Esempio n. 21
0
        public async Task <IActionResult> Create([Bind("Id,title,author,writtenyear,edition,price")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
Esempio n. 22
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price,Description")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
 public ActionResult Create([Bind("OrderId,PizzaId,StoreId,UserId,TimeStamp")] Order order)
 {
     if (ModelState.IsValid)
     {
         _context.Add(order);
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["PizzaId"] = new SelectList(_context.Set <Pizza>(), "PizzaId", "PizzaId", order.PizzaId);
     ViewData["StoreId"] = new SelectList(_context.Set <StoreLocation>(), "StoreId", "StoreId", order.StoreId);
     ViewData["UserId"]  = new SelectList(_context.Set <User>(), "UserId", "UserId", order.UserId);
     return(View(order));
 }
        public void Test_GetCustomerOrderHistory()
        {
            var options = new DbContextOptionsBuilder <OrderContext>()
                          .UseInMemoryDatabase(databaseName: "TestDb15")
                          .Options;
            var options1 = new DbContextOptionsBuilder <StoreContext>()
                           .UseInMemoryDatabase(databaseName: "TestDb15")
                           .Options;
            var options2 = new DbContextOptionsBuilder <CustomerContext>()
                           .UseInMemoryDatabase(databaseName: "TestDb15")
                           .Options;

            using (var context = new OrderContext(options))
            {
                using (var context1 = new StoreContext(options1))
                {
                    using (var context2 = new CustomerContext(options2))
                    {
                        context.Database.EnsureDeleted();
                        context.Database.EnsureCreated();
                        context1.Database.EnsureDeleted();
                        context1.Database.EnsureCreated();
                        context2.Database.EnsureDeleted();
                        context2.Database.EnsureCreated();

                        OrderRepository    orderRepo = new OrderRepository(context);
                        StoreRepository    storeRepo = new StoreRepository(context1);
                        CustomerRepository custRepo  = new CustomerRepository(context2);
                        OrderLogic         ol        = new OrderLogic(orderRepo, storeRepo, custRepo);

                        AStore   store   = new AStore();
                        Customer newCust = new Customer();

                        Order testOrder = new Order();
                        testOrder.Store          = store.StoreID;
                        testOrder.Cust           = newCust.CustomerID;
                        testOrder.JSONPizzaOrder = "this is a test order for customers";

                        context.Add <Order>(testOrder);
                        context1.Add <AStore>(store);
                        context2.Add <Customer>(newCust);
                        context.SaveChanges();
                        context1.SaveChanges();
                        context2.SaveChanges();

                        RawOrderHistory createOrder = ol.GetCustomerOrderHistory(newCust.CustomerID);
                        Assert.Equal(testOrder.JSONPizzaOrder, createOrder.jsonPizzaOrders[0]);
                    }
                }
            }
        }
Esempio n. 25
0
        public async Task <IActionResult> SubmitOrder(Order model)
        {
            try
            {
                _orderContext.Add(model);
                await _orderContext.SaveChangesAsync();

                return(Ok(model.Id));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 26
0
        public IActionResult AddOrder(OrderDetail order)
        {
            System.Diagnostics.Debug.WriteLine("Controller KargoEkle - " + order.orderedItem);
            using (var db = new OrderContext(_iconfiguration))
            {
                db.Add(order);
                db.SaveChanges();
                Console.WriteLine("DB isert completed: " +
                                  order.orderId + "," +
                                  order.orderedItem + "," +
                                  order.destAdress);
            }

            return(View("DisplayOrders", RetrieveOrders()));
        }
Esempio n. 27
0
        public async Task <IActionResult> Create(OrderModel orderModel)
        {
            if (ModelState.IsValid)
            {
                orderModel.Date             = DateTime.Today;
                orderModel.Done             = false;
                orderModel.IdOfOrderedBooks = HttpContext.Session.GetString("basket");
                orderModel.Amount           = (double)HttpContext.Session.GetInt32("amount") / 100;
                _context.Add(orderModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction("index", "home"));
            }
            return(View(orderModel));
        }
Esempio n. 28
0
        public async Task <IActionResult> Create([Bind("Id,CustomerId,ProductId,amount,Order_date")] Order order)
        {
            if (ModelState.IsValid)
            {
                order.Order_date = DateTime.Now;
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(RedirectToAction(nameof(Create)));
            }
        }
Esempio n. 29
0
        public IActionResult Cart(string[] datas)
        {
            OrderContext orderContext = new OrderContext();
            List <Order> userOrders   = new List <Order>();
            Order        order        = new Order();
            Random       rand         = new Random();

            order.NameReciver = datas[0];
            order.Adress      = datas[1];
            order.Phone       = datas[2];
            order.NumberOrder = rand.Next(0, 1000);

            _logger.LogInformation("Getting data about cart from cache.");

            ordersPizza      = (List <PizzaCount>)_cache.Get(KEY_CACHING);
            order.TotalPrice = getTotalPrice();

            _logger.LogInformation("Finally, fill data about order.");
            for (int i = 0; i < ordersPizza.Count; i++)
            {
                Order nonChangableOrder = new Order(order);
                if (ordersPizza[i].count != 0)
                {
                    nonChangableOrder.PizzaID = ordersPizza[i].pizza.ID;
                    nonChangableOrder.Count   = ordersPizza[i].count;

                    userOrders.Add(nonChangableOrder);
                }
            }

            _logger.LogInformation("Adding to DB data.");
            foreach (Order userOrder in userOrders)
            {
                orderContext.Add(userOrder);
            }

            if (orderContext.SaveChanges() != 0)
            {
                _logger.LogInformation("Clear cache");
                _cache.Remove(KEY_CACHING);
            }
            else
            {
                _logger.LogWarning("Data not written to DB.");
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 30
0
        public IActionResult Add(AddOrderModel model)
        {
            var orderToAdd = new Order {
                AccountId  = accountContext.findIdByLogin(User.Identity.Name),
                ShortDesc  = model.ShortDesc,
                LongDesc   = model.LongDesc,
                Price      = model.Price,
                Date       = model.Date,
                CategoryId = model.CategoryId
            };

            orderContext.Add(orderToAdd);
            orderContext.SaveChanges();

            return(RedirectToAction("Success", "Order"));
        }