Esempio n. 1
0
        public bool UpdateOrder(int orderId, string orderStatus, List <List <string> > orderlines, string description)
        {
            Order orderResult = orders.Find(x => x.Id == orderId);

            Status.TryParse(orderStatus, out Status status);
            orderResult.OrderStatus = status;
            orderResult.Description = description;

            orderResult.orderlines = new List <Orderline>();
            if (!databaseRepo.RemoveOrderlines(orderResult.Id))
            {
                return(false);
            }
            if (!databaseRepo.UpdateOrder(orderResult.Id, orderResult.OrderStatus.ToString(), orderResult.Description))
            {
                return(false);
            }

            foreach (List <string> orderline in orderlines)
            {
                RegisterUsedMaterial(orderResult.Id, int.Parse(orderline[0]), int.Parse(orderline[2]));
                int.TryParse(orderline[0], out int materialId);
                int.TryParse(orderline[2], out int quantity);
                if (!databaseRepo.InsertOrderline(orderResult.Id, materialId, quantity))
                {
                    return(false);
                }
            }

            return(true);
        }