public async Task<IActionResult> Edit(int id, [Bind("ID,Name,Description,Price,ImageName")] ProductCore productCore)
        {
            if (id != productCore.ID)
            {
                return NotFound();
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productCore);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductCoreExists(productCore.ID))
                    {
                        return NotFound();
                    }
                    else
                    {
                        throw;
                    }
                }
                return RedirectToAction("Index");
            }
            return View(productCore);
        }
 public async Task<IActionResult> Create([Bind("ID,Name,Description,Price,ImageName")] ProductCore productCore)
 {
     if (ModelState.IsValid)
     {
         _context.Add(productCore);
         await _context.SaveChangesAsync();
         return RedirectToAction("Index");
     }
     return View(productCore);
 }
Ejemplo n.º 3
0
        public HttpStatusCode Post(Product product)
        {
            ProductCore productCore = new ProductCore();

            if (productCore.AddProduct(product) > 0)
            {
                return(HttpStatusCode.OK);
            }
            else
            {
                return(HttpStatusCode.InternalServerError);
            }
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> Create([FromBody] Product product)
        {
            try
            {
                var response = await ProductCore.CreateAsync(product).ConfigureAwait(false);

                return(Ok(response));
            }
            catch (Exception e)
            {
                LogHelper.LogException <ProductController>(e);

                return(Ok(ResponseFactory <Product> .CreateResponse(false, ResponseCode.Error)));
            }
        }
Ejemplo n.º 5
0
        public HttpStatusCode Delete(int productId)
        {
            ProductCore productCore = new ProductCore();
            Product     product     = new Product()
            {
                ProductID = productId
            };

            if (productCore.RemoveProduct(product) > 0)
            {
                return(HttpStatusCode.OK);
            }
            else
            {
                return(HttpStatusCode.InternalServerError);
            }
        }
Ejemplo n.º 6
0
        public void GetProductShouldReturnProduct()
        {
            IProductRepository productRepository = Substitute.For <IProductRepository>();
            IBarCodeRepository codeRepository    = Substitute.For <IBarCodeRepository>();
            IInventoryItemCore inventoryCore     = Substitute.For <IInventoryItemCore>();
            IMapper            mapper            = Substitute.For <IMapper>();

            string products = Data.ResourceManager.GetString("Products");
            IEnumerable <Product> lstProducts = JsonConvert.DeserializeObject <IEnumerable <Product> >(products);

            productRepository.Find(1).Returns(lstProducts.First(lp => lp.Id == 1));

            IProductCore controller = new ProductCore(productRepository, codeRepository, inventoryCore, mapper);

            var result = controller.Find(1);

            result.ProductId.Should().Be(1);
        }
Ejemplo n.º 7
0
        public void GetProductsShouldReturnAllProducts()
        {
            IProductRepository productRepository = Substitute.For <IProductRepository>();
            IBarCodeRepository codeRepository    = Substitute.For <IBarCodeRepository>();
            IInventoryItemCore inventoryCore     = Substitute.For <IInventoryItemCore>();
            IMapper            mapper            = Substitute.For <IMapper>();

            string products = Data.ResourceManager.GetString("Products");
            IEnumerable <Product> lstProducts = JsonConvert.DeserializeObject <IEnumerable <Product> >(products);

            productRepository.GetAll().Returns(lstProducts);

            IProductCore controller = new ProductCore(productRepository, codeRepository, inventoryCore, mapper);

            var result = controller.GetAll();

            result.Should().HaveCount(4);
        }
Ejemplo n.º 8
0
        public async Task <IHttpActionResult> GetAll()
        {
            try
            {
                var response = await ProductCore.GetAllAsync(new[]
                {
                    nameof(Product.ValueAddedTax)
                }).ConfigureAwait(false);

                return(Ok(response));
            }
            catch (Exception e)
            {
                LogHelper.LogException <ProductController>(e);

                return(Ok(ResponseFactory <IList <Product> > .CreateResponse(false, ResponseCode.Error)));
            }
        }
Ejemplo n.º 9
0
        public async Task <IHttpActionResult> Get()
        {
            try
            {
                var productsResponse = await ProductCore.GetAllAsync().ConfigureAwait(false);

                var ordersResponse = await OrderCore.GetAllAsync().ConfigureAwait(false);

                var orderItemsResponse = await OrderItemCore.GetAllAsync().ConfigureAwait(false);

                var clientsResponse = await ClientCore.GetAllAsync().ConfigureAwait(false);

                var paymentsResponse = await PayrollCore.GetAllAsync().ConfigureAwait(false);

                if (!productsResponse.Success || !orderItemsResponse.Success || !orderItemsResponse.Success || !clientsResponse.Success ||
                    !paymentsResponse.Success)
                {
                    return(Ok(ResponseFactory.CreateResponse(false, ResponseCode.Error)));
                }

                var totalIncomeValue = paymentsResponse.Data.Sum(payment => payment.Value);
                var totalOrdersValue = orderItemsResponse.Data.Sum(orderItem => orderItem.Price * orderItem.Quantity);

                var model = new SummaryModel
                {
                    NumberOfClients  = clientsResponse.Data.Count,
                    NumberOfOrders   = ordersResponse.Data.Count,
                    NumberOfPayments = paymentsResponse.Data.Count,
                    NumberOfProducts = productsResponse.Data.Count,
                    TotalIncomeValue = totalIncomeValue,
                    TotalOrdersValue = totalOrdersValue
                };

                return(Ok(ResponseFactory <SummaryModel> .CreateResponse(true, ResponseCode.Success, model)));
            }
            catch (Exception e)
            {
                LogHelper.LogException <SummaryController>(e);

                return(Ok(ResponseFactory <SummaryModel> .CreateResponse(false, ResponseCode.Error)));
            }
        }
Ejemplo n.º 10
0
        public void InitializeMockData()
        {
            try
            {
                Task.Run(async() =>
                {
                    var existingProducts = await ProductCore.GetAllAsync().ConfigureAwait(false);
                    if (existingProducts.Data != null && existingProducts.Data.Count != 0)
                    {
                        return;
                    }

                    var products = await ProductCore.CreateAsync(mProducts, true).ConfigureAwait(false);

                    var existingClients = await ClientCore.GetAllAsync().ConfigureAwait(false);
                    if (existingClients.Data != null && existingClients.Data.Count != 0)
                    {
                        return;
                    }

                    var currencies = await CurrencyCore.GetAllAsync().ConfigureAwait(false);
                    if (!currencies.Success || currencies.Data == null || currencies.Data.Count == 0)
                    {
                        return;
                    }

                    var currency = currencies.Data.FirstOrDefault(c => c.Name == "RON");
                    if (currency == null)
                    {
                        return;
                    }

                    foreach (var client in mClients)
                    {
                        client.CurrencyId = currency.Id;
                    }

                    var clients = await ClientCore.CreateAsync(mClients, true).ConfigureAwait(false);

                    var existingOrders = await OrderCore.GetAllAsync().ConfigureAwait(false);
                    if (existingOrders.Data != null && existingOrders.Data.Count != 0)
                    {
                        return;
                    }

                    int nr = 0;
                    List <Order> newOrders = new List <Order>();
                    foreach (var client in clients.Data)
                    {
                        if (products.Data.Count >= 6)
                        {
                            for (int i = 0; i < 2; i++)
                            {
                                nr++;
                                var o = new Order()
                                {
                                    Id         = Guid.NewGuid(),
                                    CurrencyId = currency.Id,
                                    ClientId   = client.Id,
                                    SaleType   = i,
                                    Status     = 0,
                                    Date       = DateTime.Now.AddDays(-nr).AddHours(-nr),
                                    OrderItems = new List <OrderItem>()
                                };

                                for (int k = i + nr / 2; k < 6; k += 1)
                                {
                                    o.OrderItems.Add(new OrderItem()
                                    {
                                        Id        = Guid.NewGuid(),
                                        OrderId   = o.Id,
                                        ProductId = products.Data.ElementAt(k).Id,
                                        Price     = products.Data.ElementAt(k).Price,
                                        Quantity  = k + 1
                                    });
                                }

                                newOrders.Add(o);
                            }
                        }
                    }

                    var orders = await OrderCore.CreateAsync(newOrders, true, new[] { nameof(Order.OrderItems) }).ConfigureAwait(false);

                    var payrolls = new List <Payroll>();
                    if (orders.Data.Count > 3)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            var payroll = new Payroll()
                            {
                                Id       = Guid.NewGuid(),
                                ClientId = clients.Data.ElementAt(i).Id,
                                OrderId  = orders.Data.ElementAt(i).Id,
                                Date     = DateTime.Now.AddDays(-i),
                                Value    = orders.Data.ElementAt(i).OrderItems.Sum(p => p.Price * p.Quantity),
                            };

                            payrolls.Add(payroll);
                        }
                    }

                    await PayrollCore.CreateAsync(payrolls, true).ConfigureAwait(false);
                }).ConfigureAwait(false).GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                // ignored
            }
        }
Ejemplo n.º 11
0
        public override async Task ProcessActivityAsync(IStatus status)
        {
            var updateDownloadsTask = await statusController.CreateAsync(
                status,
                $"Update {context} downloads");

            var getSourcesTask = await statusController.CreateAsync(
                updateDownloadsTask,
                $"Get {context} download sources");

            var downloadSources = await getDownloadSourcesAsyncDelegate.GetDownloadSourcesAsync(getSourcesTask);

            await statusController.CompleteAsync(getSourcesTask);

            var counter = 0;

            foreach (var downloadSource in downloadSources)
            {
                // don't perform expensive updates if there are no actual sources
                if (downloadSource.Value != null &&
                    downloadSource.Value.Count == 0)
                {
                    continue;
                }

                var id = downloadSource.Key;

                ProductCore product = await productsDataController.GetByIdAsync(id, updateDownloadsTask);

                if (product == null)
                {
                    product = await accountProductsDataController.GetByIdAsync(id, updateDownloadsTask);

                    if (product == null)
                    {
                        await statusController.WarnAsync(
                            updateDownloadsTask,
                            $"Downloads are scheduled for the product/account product {id} that doesn't exist");

                        continue;
                    }
                }

                await statusController.UpdateProgressAsync(
                    updateDownloadsTask,
                    ++counter,
                    downloadSources.Count,
                    product.Title);

                var productDownloads = await productDownloadsDataController.GetByIdAsync(product.Id, updateDownloadsTask);

                if (productDownloads == null)
                {
                    productDownloads = new ProductDownloads
                    {
                        Id        = product.Id,
                        Title     = product.Title,
                        Downloads = new List <ProductDownloadEntry>()
                    };
                }

                // purge existing downloads for this download type as we'll always be scheduling all files we need to download
                // and don't want to carry over any previously scheduled files that might not be relevant anymore
                // (e.g. files that were scheduled, but never downloaded and then removed from data files)
                var existingDownloadsOfType = productDownloads.Downloads.FindAll(
                    d => d.Context == context).ToArray();
                foreach (var download in existingDownloadsOfType)
                {
                    productDownloads.Downloads.Remove(download);
                }

                var scheduleDownloadsTask = await statusController.CreateAsync(
                    updateDownloadsTask,
                    "Schedule new downloads");

                foreach (var source in downloadSource.Value)
                {
                    var destinationDirectory = getDirectoryDelegate?.GetDirectory(source);

                    var scheduledDownloadEntry = new ProductDownloadEntry
                    {
                        Context     = context,
                        SourceUri   = source,
                        Destination = destinationDirectory
                    };

                    var destinationUri = Path.Combine(
                        destinationDirectory,
                        Path.GetFileName(source));

                    // we won't schedule downloads for the already existing files
                    // we won't be able to resolve filename for productFiles, but that should cut off
                    // number of images we constantly try to redownload
                    if (fileController.Exists(destinationUri))
                    {
                        continue;
                    }

                    productDownloads.Downloads.Add(scheduledDownloadEntry);
                }

                await productDownloadsDataController.UpdateAsync(productDownloads, scheduleDownloadsTask);

                await statusController.CompleteAsync(scheduleDownloadsTask);
            }

            await statusController.CompleteAsync(updateDownloadsTask);
        }
Ejemplo n.º 12
0
        public IEnumerable <Product> Get(string id)
        {
            ProductCore productCore = new ProductCore();

            return(productCore.GetProductsFacade(ProductAction.GetProductsForProductTypeID, id));
        }
Ejemplo n.º 13
0
        public IEnumerable <Product> Get()
        {
            ProductCore productCore = new ProductCore();

            return(productCore.GetProductsFacade(ProductAction.GetAllProducts).ToList <Product>());
        }
Ejemplo n.º 14
0
        public string Get(int id)
        {
            ProductCore productCore = new ProductCore();

            return(productCore.GetPrice(id));
        }
Ejemplo n.º 15
0
 public async Task <ProductCore> Update(ProductCore entity)
 {
     return(_mapper.Map <ProductCore>(await _repository.Update(_mapper.Map <Product>(entity))));
 }
Ejemplo n.º 16
0
 public async Task Delete(ProductCore entity)
 {
     await _repository.Delete(_mapper.Map <Product>(entity));
 }