Esempio n. 1
0
 public IActionResult CompleteOrder(Guid id)
 {
     try
     {
         var user = uEngine.GetUser(this.User.FindFirst(ClaimTypes.Email).Value);
         if (engine.CompleteOrder(user, id) != null)
         {
             return(Ok());
         }
         else
         {
             return(BadRequest());
         }
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex.Message));
     }
 }
Esempio n. 2
0
        private void SeedProductsAndOrders()
        {
            if (context.Products.Count() == 0)
            {
                // Seed Products
                var userValentin = uEngine.GetUser("*****@*****.**");
                var userClarence = uEngine.GetUser("*****@*****.**");
                var userKairon   = uEngine.GetUser("*****@*****.**");
                var userGemma    = uEngine.GetUser("*****@*****.**");
                var userMisbah   = uEngine.GetUser("*****@*****.**");
                var userDonte    = uEngine.GetUser("*****@*****.**");
                var userTyler    = uEngine.GetUser("*****@*****.**");
                var userKiya     = uEngine.GetUser("*****@*****.**");
                var userBradley  = uEngine.GetUser("*****@*****.**");
                var userSania    = uEngine.GetUser("*****@*****.**");
                var userKerri    = uEngine.GetUser("*****@*****.**");
                var userTessa    = uEngine.GetUser("*****@*****.**");
                var userKhloe    = uEngine.GetUser("*****@*****.**");
                var userReef     = uEngine.GetUser("*****@*****.**");
                var userBobbie   = uEngine.GetUser("*****@*****.**");
                var userDamian   = uEngine.GetUser("*****@*****.**");
                var userLorena   = uEngine.GetUser("*****@*****.**");
                var userKelly    = uEngine.GetUser("*****@*****.**");
                var userCharlton = uEngine.GetUser("*****@*****.**");
                var userRubie    = uEngine.GetUser("*****@*****.**");
                var userThiago   = uEngine.GetUser("*****@*****.**");

                string          jsonString;
                ProductResource product;

                jsonString = System.IO.File.ReadAllText(@".\Data\productChicken.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productChicken = pEngine.PostProduct(
                    userClarence,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-8)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productCurd.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productCurd = pEngine.PostProduct(
                    userKairon,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-7)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productHoney.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productHoney = pEngine.PostProduct(
                    userGemma,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-6)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productApplePie.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productApplePie = pEngine.PostProduct(
                    userMisbah,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-6)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productSweetBread.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productSweetBread = pEngine.PostProduct(
                    userDonte,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-6)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productGreenSpaceMaintenance.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productGreenSpaceMaintenance = pEngine.PostProduct(
                    userValentin,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-9)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productBread.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productBread = pEngine.PostProduct(
                    userTyler,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-5)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productCabbageVineRolls.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productCabbageVineRolls = pEngine.PostProduct(
                    userKiya,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-4)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productStrawberries.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productStrawberries = pEngine.PostProduct(
                    userBradley,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-3)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productFilledNutsCookies.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productFilledNutsCookies = pEngine.PostProduct(
                    userSania,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-3)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productGardenSet.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productGardenSet = pEngine.PostProduct(
                    userKerri,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-3)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productNailSaloon.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productNailSaloon = pEngine.PostProduct(
                    userTessa,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-2)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productFriedChicken.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productFriedChicken = pEngine.PostProduct(
                    userKhloe,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-1)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productCleanupServices.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productCleanupServices = pEngine.PostProduct(
                    userReef,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-1)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productLandscaping.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productLandscaping = pEngine.PostProduct(
                    userBobbie,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-1)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productFlowerBouquets.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productFlowerBouquets = pEngine.PostProduct(
                    userDamian,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today.AddDays(-1)
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productTomatoSeedlings.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productTomatoSeedlings = pEngine.PostProduct(
                    userLorena,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productMiniHouse.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productMiniHouse = pEngine.PostProduct(
                    userKelly,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productStrawberryCake.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productStrawberryCake = pEngine.PostProduct(
                    userCharlton,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today
                    );

                jsonString = System.IO.File.ReadAllText(@".\Data\productGirlHeadbands.json");
                product    = JsonConvert.DeserializeObject <ProductResource>(jsonString);
                var productGirlHeadbands = pEngine.PostProduct(
                    userRubie,
                    new Product()
                {
                    Name = product.Name, Type = product.Type, Quantity = product.Quantity, Price = product.Price, Description = product.Description
                },
                    product.Images.Select(i => new ImageDetail()
                {
                    Description = i.Description,
                    Type        = i.Type,
                    Image       = Convert.FromBase64String(i.Image)
                }).ToList(),
                    DateTime.Today
                    );

                //Seed Orders
                // To fulfill admin
                var orderGreenSpaceMaintenance1 = oEngine.PlaceOrder(userClarence, new Models.DTOs.OrderDTO()
                {
                    ProductId      = productGreenSpaceMaintenance.Id,
                    Quantity       = 1,
                    ContactName    = $"{this.protector.Unprotect(userClarence.FirstName)} {this.protector.Unprotect(userClarence.LastName)}",
                    ContactAddress = "Ethernet Str.",
                    ContactPhone   = "0770111111"
                }, DateTime.Today.AddDays(-8));
                var orderGreenSpaceMaintenance2 = oEngine.PlaceOrder(userKairon, new Models.DTOs.OrderDTO()
                {
                    ProductId      = productGreenSpaceMaintenance.Id,
                    Quantity       = 1,
                    ContactName    = $"{this.protector.Unprotect(userKairon.FirstName)} {this.protector.Unprotect(userKairon.LastName)}",
                    ContactAddress = "Ethernet Str.",
                    ContactPhone   = "0770111111"
                }, DateTime.Today.AddDays(-7));
                var orderGreenSpaceMaintenance3 = oEngine.PlaceOrder(userGemma, new Models.DTOs.OrderDTO()
                {
                    ProductId      = productGreenSpaceMaintenance.Id,
                    Quantity       = 1,
                    ContactName    = $"{this.protector.Unprotect(userGemma.FirstName)} {this.protector.Unprotect(userGemma.LastName)}",
                    ContactAddress = "Ethernet Str.",
                    ContactPhone   = "0770111111"
                }, DateTime.Today.AddDays(-6));
                var orderGreenSpaceMaintenance4 = oEngine.PlaceOrder(userMisbah, new Models.DTOs.OrderDTO()
                {
                    ProductId      = productGreenSpaceMaintenance.Id,
                    Quantity       = 1,
                    ContactName    = $"{this.protector.Unprotect(userMisbah.FirstName)} {this.protector.Unprotect(userMisbah.LastName)}",
                    ContactAddress = "Ethernet Str.",
                    ContactPhone   = "0770111111"
                }, DateTime.Today.AddDays(-6));
                var orderGreenSpaceMaintenance5 = oEngine.PlaceOrder(userDonte, new Models.DTOs.OrderDTO()
                {
                    ProductId      = productGreenSpaceMaintenance.Id,
                    Quantity       = 1,
                    ContactName    = $"{this.protector.Unprotect(userDonte.FirstName)} {this.protector.Unprotect(userDonte.LastName)}",
                    ContactAddress = "Ethernet Str.",
                    ContactPhone   = "0770111111"
                }, DateTime.Today.AddDays(-5));
                var orderGreenSpaceMaintenance6 = oEngine.PlaceOrder(userTyler, new Models.DTOs.OrderDTO()
                {
                    ProductId      = productGreenSpaceMaintenance.Id,
                    Quantity       = 1,
                    ContactName    = $"{this.protector.Unprotect(userTyler.FirstName)} {this.protector.Unprotect(userTyler.LastName)}",
                    ContactAddress = "Ethernet Str.",
                    ContactPhone   = "0770111111"
                }, DateTime.Today.AddDays(-4));

                oEngine.CompleteOrder(userValentin, orderGreenSpaceMaintenance1.Id, DateTime.Today.AddDays(-7));
                oEngine.CompleteOrder(userValentin, orderGreenSpaceMaintenance2.Id, DateTime.Today.AddDays(-6));
                oEngine.CompleteOrder(userValentin, orderGreenSpaceMaintenance3.Id, DateTime.Today.AddDays(-5));
                oEngine.CancelOrder(userMisbah, orderGreenSpaceMaintenance4.Id, "No longer required", DateTime.Today.AddDays(-5));

                // To receive admin
                var orderChicken = oEngine.PlaceOrder(userValentin, new Models.DTOs.OrderDTO()
                {
                    ProductId      = productChicken.Id,
                    Quantity       = 2,
                    ContactName    = $"{this.protector.Unprotect(userValentin.FirstName)} {this.protector.Unprotect(userValentin.LastName)}",
                    ContactAddress = "Ethernet Str.",
                    ContactPhone   = "0770111111"
                }, DateTime.Today.AddDays(-3));
                var orderApplePie = oEngine.PlaceOrder(userValentin, new Models.DTOs.OrderDTO()
                {
                    ProductId      = productApplePie.Id,
                    Quantity       = 1,
                    ContactName    = $"{this.protector.Unprotect(userValentin.FirstName)} {this.protector.Unprotect(userValentin.LastName)}",
                    ContactAddress = "Ethernet Str.",
                    ContactPhone   = "0770111111"
                }, DateTime.Today.AddDays(-3));
                var orderFriedChicken = oEngine.PlaceOrder(userValentin, new Models.DTOs.OrderDTO()
                {
                    ProductId      = productFriedChicken.Id,
                    Quantity       = 1,
                    ContactName    = $"{this.protector.Unprotect(userValentin.FirstName)} {this.protector.Unprotect(userValentin.LastName)}",
                    ContactAddress = "Ethernet Str.",
                    ContactPhone   = "0770111111"
                }, DateTime.Today.AddDays(-1));
                var orderFlowerBouquets = oEngine.PlaceOrder(userValentin, new Models.DTOs.OrderDTO()
                {
                    ProductId      = productFlowerBouquets.Id,
                    Quantity       = 1,
                    ContactName    = $"{this.protector.Unprotect(userValentin.FirstName)} {this.protector.Unprotect(userValentin.LastName)}",
                    ContactAddress = "Ethernet Str.",
                    ContactPhone   = "0770111111"
                }, DateTime.Today);
            }
        }