Example #1
0
        public UserProductsViewModel                        Make_UserProductsViewModel(Product product)
        {
            Employee driver = null;
            string   login  = "";

            foreach (var el in IoC.Application_Work.All_Users)
            {
                if (el is Client client && client?.Products.FirstOrDefault(u => u.Id == product.Id) != null)
                {
                    login = el.Login;
                }
            }
            var route = IoC.Application_Work.All_Routes.FirstOrDefault(r => r.Product?.Id == product.Id);
            var car   = IoC.Application_Work.All_Cars.FirstOrDefault(r => r.Routes.FirstOrDefault(rot => rot?.Id == route?.Id)?.Id == route?.Id);

            foreach (var dr in IoC.Application_Work.All_Users)
            {
                if (dr is Employee driv && driv?.CarId == car?.Id)
                {
                    driver = (dr as Employee);
                }
            }
            return(new UserProductsViewModel
            {
                Initials = "CL",
                ProfilePictureRGB = "89ccb7",
                Status = StringCheck.Convert_Order_Status(product.Status == StatusOfProduct.Inpprocessing ? StatusOfProduct.DispetcherInpprocessing : product.Status),
                UserName = login,
                StatusColor = product.Status == StatusOfProduct.Completed ? "00c541" : product.Status == StatusOfProduct.Current ? "ff4747" : "0080ff",
                ProductName = product.Name,
                Product = product,
                OrderDialogViewModel = new OrderDialogViewModel
                {
                    OrderName = product.Name ?? "Empty",
                    OrderWeight = product.ProductWeight.ToString() ?? "Empty",
                    From = route != null ? route.From : "Empty",
                    To = route != null ? route.To : "Empty",
                    DeliveryDate = route != null ? DateTime.Parse(route.DepartureDate.ToString()).ToShortDateString() : "Empty",
                    DeliveryCost = route?.DeliveryCost.ToString() ?? "Empty",
                    CarBrand = car?.CarBrand ?? "Empty",
                    CarNumber = car?.CarNumber ?? "Empty",
                    DispetcherName = car?.CarBrand ?? "Empty",
                    DriverName = driver?.FullName ?? "Empty",
                    AdoptionDate = car?.Routes.FirstOrDefault(rot => rot?.Id == route?.Id)?.ArrivalDate.ToShortDateString() ?? "Empty",
                },
                ShowVariablesOfDialog = StringCheck.Convert_Order_Status_To_Dialog(product.Status == StatusOfProduct.Inpprocessing ? StatusOfProduct.DispetcherInpprocessing : product.Status),
            });
        }