Exemple #1
0
        public async Task <ProductprEntity> SaveProduct(ProductprEntity product)
        {
            var productFromDb = await Query.Where(e => e.Id == product.Id).FirstOrDefaultAsync();

            if (productFromDb == null)
            {
                return((await SaveEntity(product.ToProductpr(null))).ToProductprEntity());
            }
            else
            {
                return((await SaveEntity(product.ToProductpr(productFromDb))).ToProductprEntity());
            }
        }
Exemple #2
0
        public static ProductprViewModel ToProductprViewModel(this ProductprEntity orderEntity)
        {
            ProductprViewModel model = new ProductprViewModel();

            model.Id              = orderEntity.Id;
            model.Name            = orderEntity.Name;
            model.Parentid        = orderEntity.Parentid;
            model.Price           = orderEntity.Price;
            model.ShelfLife       = orderEntity.ShelfLife;
            model.CountryOfOrigin = orderEntity.CountryOfOrigin;
            model.AvailableAmount = orderEntity.AvailableAmount;
            return(model);
        }
        public static Productpr ToProductpr(this ProductprEntity orderEntity, Productpr dbmodel = null)
        {
            Productpr model = dbmodel;

            if (model == null)
            {
                model = new Productpr();
            }
            model.Name            = orderEntity.Name;
            model.Parentid        = orderEntity.Parentid;
            model.CountryOfOrigin = orderEntity.CountryOfOrigin;
            model.Price           = orderEntity.Price;
            model.ShelfLife       = orderEntity.ShelfLife;
            model.AvailableAmount = orderEntity.AvailableAmount;
            return(model);
        }
Exemple #4
0
        public async Task <IActionResult> MakePurchase(Product2ViewModel model)
        {
            try
            {
                ProductprEntity      entity            = new ProductprEntity();
                PurchaseEntity       purchaseEntity    = new PurchaseEntity();
                List <ProductEntity> productEntityList = new List <ProductEntity>();
                int?totalSum = 0;
                foreach (var item in model.productprViewModels)
                {
                    if (item.AvailableAmount != 0)
                    {
                        entity = await _dm.ProductprAccessor.GetPrId(item.Id);

                        entity.AvailableAmount -= item.AvailableAmount;
                        item.Price              = entity.Price;
                        item.CountryOfOrigin    = entity.CountryOfOrigin;
                        item.ShelfLife          = entity.ShelfLife;
                        item.Name = entity.Name;
                        entity    = await _dm.ProductprAccessor.SaveProduct(entity);
                    }
                }
                for (int i = 0; i <= model.productprViewModels.Count - 1; i++)
                {
                    if (model.productprViewModels[i].AvailableAmount != 0)
                    {
                        productEntityList.Add((model.productprViewModels[i]).ToProductEntity());
                        totalSum += model.productprViewModels[i].Price * model.productprViewModels[i].AvailableAmount;
                    }
                }

                purchaseEntity.Provider    = "AlkoMarket";
                purchaseEntity.IsExecuted  = false;
                purchaseEntity.ProductList = productEntityList;
                purchaseEntity.TotalSum    = totalSum ?? default(int);

                purchaseEntity = await _dm.PurchaseAccessor.SavePuchase(purchaseEntity);


                return(new OkObjectResult(purchaseEntity));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public static ProductprEntity ToProductprEntity(this Productpr model)
        {
            if (model == null)
            {
                return(null);
            }
            ProductprEntity orderEntity = new ProductprEntity();

            orderEntity.Id              = model.Id;
            orderEntity.Name            = model.Name;
            orderEntity.Parentid        = model.Parentid;
            orderEntity.CountryOfOrigin = model.CountryOfOrigin;
            orderEntity.Price           = model.Price;
            orderEntity.ShelfLife       = model.ShelfLife;
            orderEntity.AvailableAmount = model.AvailableAmount;
            return(orderEntity);
        }