Beispiel #1
0
        public ActionResult AddOrder(int idClient, OrderRequest orderRequest)
        {
            if (!_context.Clients.Any(x => x.IdClient == idClient))
            {
                return(BadRequest("Podany klient nie istnieje"));
            }

            bool anyExists = false;

            orderRequest.Confectioneries.ForEach(
                x =>
            {
                Console.WriteLine(x.Name);
                if (!_context.Confectioneries.Any(c => c.Name.Equals(x.Name)))
                {
                    anyExists = true;
                }
            }
                );

            if (anyExists)
            {
                return(BadRequest("Podany wybór nie istnieje"));
            }

            using (var transaction = _context.Database.BeginTransaction()) {
                var newOrder = new Order
                {
                    DateOfAdmission   = orderRequest.DateOfAdmission,
                    Comments          = orderRequest.Comments,
                    DateOfRealization = DateTime.Now,
                    IdClient          = idClient,
                    IdEmployee        = 1
                };

                _context.Orders.Add(newOrder);
                _context.SaveChanges();

                orderRequest.Confectioneries.ForEach(
                    x =>
                {
                    Confectionery c        = _context.Confectioneries.Where(c => c.Name.Equals(x.Name)).FirstOrDefault();
                    var orderConfectionery = new OrderConfectionery
                    {
                        IdConfectionery = c.IdConfectionery,
                        IdOrder         = newOrder.IdOrder,
                        Quantity        = x.Quantity
                    };

                    _context.OrderConfectioneries.Add(orderConfectionery);
                }
                    );

                _context.SaveChanges();

                transaction.Commit();
            }

            return(Ok("Dodano dane"));
        }
 public override void Prepare()
 {
     Console.WriteLine("Preparing " + Name);
     Muffins      = Confectionery.MakeMuffins(10);
     Profiteroles = Confectionery.MakeProfiteroles(10);
     Cake         = Confectionery.MakeCake();
 }
Beispiel #3
0
        private string SmsOrder(string item)
        {
            Confectionery c = inventory.Find(x => x.Name == item);

            if (c.Nr > 0)
            {
                c.Nr--;
                return($"Giving {c.Name} out.");
            }
            return($"No more {c.Name} left");
        }
Beispiel #4
0
        private OrderItemResponse buildOrderItemResponse(ConfectioneryOrder confOrder)
        {
            Confectionery     confectionery = _context.Confectioneries.Where(c => c.IdConfecti == confOrder.IdConfection).First();
            OrderItemResponse response      = new OrderItemResponse()
            {
                ConfectioneryName = confectionery.Name,
                Type     = confectionery.Type,
                Quantity = confOrder.Quantity
            };

            return(response);
        }
        private int CreateNewConfectioneryOrder(int idOrder, ConfectioneryRequest confectioneryRequest)
        {
            Confectionery confectionery =
                _context.Confectionery.FirstOrDefault(c => c.Name == confectioneryRequest.Name);

            _context.Confectionery_Order.Add(new Confectionery_Order
            {
                IdConfectionery = confectionery.IdConfectionery,
                IdOrder         = idOrder,
                Quantity        = Convert.ToInt32(confectioneryRequest.Quantity),
                Notes           = confectioneryRequest.Notes
            });
            _context.SaveChanges();
            return(confectionery.IdConfectionery);
        }
Beispiel #6
0
        public IActionResult addClient(String clientid)
        {
            ClientStructure enter = new ClientStructure

            {
                DateAccepted = DateTime.Parse("2020-06-01"),
                Notes        = "Please, prepare for next friday",

                Quantity = 1,
                Name     = "Cake for birthday",
                ConNotes = "Write Happy birthday on the cake"
            };

            var exc = _context.Customers.Find(clientid);

            if (exc is null)
            {
                return(NotFound(" this Client does not exist in the database"));
            }

            var od = new Order
            {
                DateAccepted = enter.DateAccepted,
                Notes        = enter.Notes,
            };

            var con_od = new Confectionery_Order
            {
                Quantity = enter.Quantity,
                Notes    = enter.ConNotes
            };

            var con = new Confectionery
            {
                Name = enter.Name
            };

            _context.Orders.Add(od);
            _context.Confectioneries.Add(con);
            _context.Confectionery_Orders.Add(con_od);

            _context.SaveChanges();

            return(Ok("Order for the client has been successfully added"));
        }
Beispiel #7
0
        private string Order(string item)
        {
            Confectionery c = inventory.Find(x => x.Name == item);

            if (c.Nr == 0)
            {
                return($"No more {c.Name} left");
            }
            if (c.Cost > money)
            {
                return($"Need " + (c.Cost - money) + " more");
            }
            c.Nr--;
            int change = money - c.Cost;

            money = 0;

            return($"Giving {c.Name} out.\n" +
                   $"Giving {change} out in change.\n");
            //$"{c.Nr} {c.Name} left";
        }