private ProductModel Transfer(Data.Entities.Product entity)
        {
            var p = new ProductModel
            {
                ProductId = entity.ProductId,
                Name      = entity.Name,
                Price     = entity.Price,
                Materials = new List <ProductMaterialModel>()
            };


            foreach (var m in entity.ProductMaterials)
            {
                var material = new ProductMaterialModel {
                    Quantity = m.Quantity
                };
                material.MaterialName = m.Material.Name;
                material.Quantity     = m.Quantity;
                material.MaterialId   = m.MaterialId;

                p.Materials.Add(material);
            }

            return(p);
        }
Пример #2
0
 public Product(Data.Entities.Product entity)
 {
     Name        = entity.Name;
     Description = entity.Description;
     Price       = entity.Price;
     Stock       = entity.Stock;
 }
Пример #3
0
 public Product(Data.Entities.Product _product)
 {
     this.Id          = _product.Id;
     this.Category    = _product.Category == null ? null : new Category(_product.Category);
     this.Name        = _product.Name?.GetLocalizationValue();
     this.Description = _product.Description?.GetLocalizationValue();
     this.Price       = _product.Price;
 }
Пример #4
0
        private OperationResult ValidateId(Data.Entities.Product product)
        {
            if ((product?.Id ?? Guid.Empty) == Guid.Empty)
            {
                return(new OperationResult("The product id is missing."));
            }

            return(null);
        }
Пример #5
0
        private int GetProductPriceInteger(Data.Entities.Product product)
        {
            switch (product.Type)
            {
            case ProductEnum.COIN_OFFER:
                return(Convert.ToInt32(product.Price * 100));

            default:
                return(0);
            }
        }
Пример #6
0
        public async Task <OperationResult> InsertAsync(Data.Entities.Product product)
        {
            var productValidation = this.ValidateNameAndBrand(product);

            if (productValidation != null)
            {
                return(productValidation);
            }

            return(await this.repository.InsertAsync(product));
        }
Пример #7
0
        public ActionResult Delete(Data.Entities.Product p)
        {
            try
            {
                this._repository.DeleteProduct(p.ID);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Пример #8
0
        public ActionResult Edit(Data.Entities.Product p)
        {
            try
            {
                this._repository.EditProduct(p);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Пример #9
0
        private OperationResult ValidateNameAndBrand(Data.Entities.Product product)
        {
            if (string.IsNullOrWhiteSpace(product?.Name))
            {
                return(new OperationResult("The product name is missing."));
            }

            if (string.IsNullOrWhiteSpace(product.Brand))
            {
                return(new OperationResult("The product brand is missing."));
            }

            return(null);
        }
Пример #10
0
        public async Task <bool> ExecutedAsync(Data.Entities.Product product)
        {
            try
            {
                db.Entry(product).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Пример #11
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Product = await _context.Products.FirstOrDefaultAsync(m => m.Id == id);

            if (Product == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Пример #12
0
        public async Task <bool> ExecutedAsync(Data.Entities.Product product)
        {
            try
            {
                await db.Products.AddAsync(product);

                await db.SaveChangesAsync();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Пример #13
0
        public ProductCardViewModel(Data.Entities.Product product)
        {
            Id           = product.Id;
            Name         = product.Name;
            Description  = product.Description;
            CategoryName = product.Category.Name;

            Discount = product.Discount;
            Price    = product.Price;

            ReviewAmount = product.Reviews.Count;
            TotalRating  = product.Reviews.Count != 0 ? product.Reviews.Sum(rev => rev.Rating) / product.Reviews.Count : 0;

            PictureUrl = product.PictureUrl;
        }
Пример #14
0
            public async Task <string> Handle(Command request, CancellationToken cancellationToken)
            {
                request.Validate();

                var product = new Data.Entities.Product
                {
                    Code        = request.Code,
                    Description = request.Description
                };

                this.context.Products.Add(product);

                await this.context.SaveChangesAsync();

                return(product.Code);
            }
Пример #15
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Product = await _context.Products.FindAsync(id);

            if (Product != null)
            {
                _context.Products.Remove(Product);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Пример #16
0
        private async Task <Data.Entities.Order> CreateOrderAsync(string externalId, User user, Data.Entities.Product product, int amount,
                                                                  string statusInformation = "", PaymentMethodEnum paymentMethod = PaymentMethodEnum.STRIPE, OrderStatusEnum status = OrderStatusEnum.PROCESING)
        {
            var order = new Data.Entities.Order
            {
                ExternalId         = externalId,
                UserId             = user.Id,
                UserEmail          = user.Email,
                UserFullName       = user.FullName,
                ProductId          = product?.Id,
                ProductName        = product?.Name,
                ProductDescription = product?.Description,
                Amount             = amount / 100m,
                Status             = status,
                StatusInformation  = statusInformation,
                PaymentMethod      = paymentMethod,
                CreatedAt          = DateTime.UtcNow,
                ModifiedAt         = DateTime.UtcNow
            };

            await _uow.OrderRepository.AddAsync(order);

            await _uow.CommitAsync();

            return(order);
        }
Пример #17
0
        /// <summary>
        /// validates the receipt and returns the list of orders generated from that receipt. All
        /// payment not tracked in the api are processed and completed.
        /// </summary>
        /// <param name="userId">user which will receive all the unprocessed payments in the receipt</param>
        /// <param name="receiptData">receipt as a base64 string</param>
        /// <returns>List of orders processed</returns>
        public async Task <IEnumerable <Data.Entities.Order> > ValidateAppleReceiptAsync(int userId, string receiptData)
        {
            var orders         = new List <Data.Entities.Order>();
            var receipt        = _appleAppStoreService.GetReceipt(receiptData);
            var isReceiptValid = _appleAppStoreService.IsReceiptValid(receipt);

            if (isReceiptValid)
            {
                var user = await _userService.GetUserAsync(userId);

                foreach (var item in receipt.Receipts)
                {
                    var applProductId             = item.ProductId;
                    Data.Entities.Product product = null;
                    // check if order does not exist and save it
                    var order = await GetOrderAsync(item.TransactionId);

                    // If order exist then this receipt was already processed
                    if (order == null)
                    {
                        switch (applProductId)
                        {
                        case "p500":
                            product = await _uow.ProductRepository.GetAll().FirstOrDefaultAsync(p => p.Value == 500 && p.Type == ProductEnum.COIN_OFFER);

                            break;

                        case "p2000":
                            product = await _uow.ProductRepository.GetAll().FirstOrDefaultAsync(p => p.Value == 2000 && p.Type == ProductEnum.COIN_OFFER);

                            break;

                        case "p3500":
                            product = await _uow.ProductRepository.GetAll().FirstOrDefaultAsync(p => p.Value == 3500 && p.Type == ProductEnum.COIN_OFFER);

                            break;

                        default:
                            break;
                        }

                        var statusInfo = "In App Purshase Completed";

                        if (product == null)
                        {
                            statusInfo = "Product not found in the server (" + applProductId + ")";
                            await CreateOrderAsync(item.TransactionId, user, product, 0, statusInfo, PaymentMethodEnum.IN_APP_PURSHASE_APPLE, OrderStatusEnum.FAILED);

                            Console.WriteLine(statusInfo);
                        }
                        else
                        {
                            var amount = GetProductPriceInteger(product);
                            order = await CreateOrderAsync(item.TransactionId, user, product, amount, statusInfo, PaymentMethodEnum.IN_APP_PURSHASE_APPLE, OrderStatusEnum.SUCCED);

                            // give coins to the user
                            await HandleCoinsIncrementActionAsync(order);

                            await _uow.CommitAsync();

                            orders.Add(order);
                        }
                    }
                }
            }

            return(orders);
        }