public void PopulateDiscount()
        {
            var apiDiscounts = HTTPRequests.GetDiscounts();

            foreach (var discount in apiDiscounts)
            {
                var newDiscount = new Discount
                {
                    Name       = discount.Name,
                    CategoryId = discount.CategoryId,
                    Policies   = new List <DiscountPolicy>()
                };

                _unitOfWork.Discount.Add(newDiscount);

                foreach (var policy in discount.Policies)
                {
                    var newPolicy = new DiscountPolicy
                    {
                        Discount   = policy.Discount,
                        DiscountId = newDiscount.Id,
                        Min        = policy.Min
                    };

                    _unitOfWork.DiscountPolicy.Add(newPolicy);
                    newDiscount.Policies.Add(newPolicy);
                }
            }

            _unitOfWork.Save();
        }
Example #2
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var dataSource = services.GetRequiredService <DataSource>();
                    dataSource.Comments = HTTPRequests.GetComments();

                    dataSource.Posts = LinqRequests.GetPostsEntity(HTTPRequests.GetPosts()
                                                                   , dataSource.Comments);

                    dataSource.Todos = HTTPRequests.GetTodos();

                    dataSource.Users = LinqRequests.GetUsersEntity(HTTPRequests.GetUsers()
                                                                   , dataSource.Posts, dataSource.Todos);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while creating data source.");
                }
            }

            host.Run();
        }
        public List <Product> PopulateProduct()
        {
            var products    = new List <Product>();
            var apiProducts = HTTPRequests.GetProducts();

            foreach (var product in apiProducts)
            {
                var newProduct = new Product
                {
                    Id          = product.Id,
                    Name        = product.Name,
                    Price       = product.Price,
                    Photo       = product.Photo,
                    IsFavourite = false,
                    CategoryId  = product.CategoryId,
                    Description = product.Description
                };

                _unitOfWork.Product.Add(newProduct);
                products.Add(newProduct);
            }

            _unitOfWork.Save();

            return(products);
        }
        public void PopulateCategories()
        {
            var apiCategories = HTTPRequests.GetCategories();

            foreach (var category in apiCategories)
            {
                var newCategory = new Category
                {
                    Id   = category.Id,
                    Name = category.Name
                };

                _unitOfWork.Category.Add(newCategory);
            }

            _unitOfWork.Save();
        }
Example #5
0
 public override void OnDestroy()
 {
     base.OnDestroy();
     requests = null;
 }
Example #6
0
 public override bool OnUnbind(Intent intent)
 {
     requests = null;
     return(base.OnUnbind(intent));
 }
Example #7
0
 public override void OnCreate()
 {
     base.OnCreate();
     requests = new HTTPRequests();
 }