public IEnumerable <Dto.Product> Get()
        {
            var prod1 = new Dto.Product
            {
                Id       = 1001,
                Name     = "Josephine Darakjy",
                Activity = 37,
                Country  = new Dto.Country {
                    Name = "Egypt", Code = "eg"
                },
                Company        = "Chanay, Jeffrey A Esq",
                Date           = DateTime.Now,
                Status         = "new",
                Representative = new Dto.Representative {
                    Name = "Amy Elsner", Image = "amyelsner.png"
                }
            };
            var prod2 = new Dto.Product
            {
                Id       = 1003,
                Name     = "Lenna Paprocki",
                Activity = 37,
                Country  = new Dto.Country {
                    Name = "Slovenia", Code = "si"
                },
                Company        = "Feltz Printing Service",
                Date           = DateTime.Now,
                Status         = "new",
                Representative = new Dto.Representative {
                    Name = "Xuxue Feng", Image = "xuxuefeng.png"
                }
            };
            var prod3 = new Dto.Product
            {
                Id       = 1003,
                Name     = "Lenna Paprocki",
                Activity = 37,
                Country  = new Dto.Country {
                    Name = "Slovenia", Code = "si"
                },
                Company        = "Feltz Printing Service",
                Date           = DateTime.Now,
                Status         = "new",
                Representative = new Dto.Representative {
                    Name = "Xuxue Feng", Image = "xuxuefeng.png"
                }
            };

            var products = new List <Dto.Product>();

            products.Add(prod1);
            products.Add(prod2);
            products.Add(prod3);
            return(products);
            //return ProductsRepo.Get().Select(Mapper.Map<Dto.Product>);
        }
Example #2
0
        public async Task <Result <bool> > Update(Dto.Product product)
        {
            try
            {
                var updateQuery = Builders <Product> .Update.Set(b => b.Name, product.Name)
                                  .Set(b => b.Price, product.Price)
                                  .Set(b => b.ModifyDate, DateTime.Now);

                var filter = Builders <Product> .Filter.Eq(b => b.Code, product.Code)
                             & Builders <Product> .Filter.Eq(b => b.Deleted, false);

                var result = await productCollection.UpdateOneAsync(filter, updateQuery);

                return(result.ModifiedCount > 0);
            }
            catch (Exception exp)
            {
                return(exp);
            }
        }
Example #3
0
        public async Task <Result <bool> > Insert(Dto.Product product)
        {
            try
            {
                long count = await productCollection.Find(item => !item.Deleted && item.Code == product.Code).CountDocumentsAsync();

                if (count > 0)
                {
                    return(new Error("Duplicate Key"));
                }
                Product newItem = mapper.Map <Product>(product);
                newItem.ModifyDate   = DateTime.Now;
                newItem.CreationDate = DateTime.Now;
                await productCollection.InsertOneAsync(newItem);

                return(true);
            }
            catch (Exception exp)
            {
                return(exp);
            }
        }
Example #4
0
        //[HttpGet("catalog/{id}/")]
        public Product Get(string id)
        {
            Models.Product product = catalogContext.Product
                                     .Include(x => x.ProductGenders).ThenInclude(x => x.Gender)
                                     .Include(x => x.Units).ThenInclude(x => x.Price)
                                     .Include(x => x.Units).ThenInclude(x => x.OriginalPrice)
                                     .Include(x => x.Brand).ThenInclude(x => x.BrandFamily)
                                     .Single(x => x.Id == id);

            Dto.Product productDto = new Dto.Product
            {
                id             = product.Id,
                modelId        = product.ModelId,
                name           = product.Name,
                shopUrl        = product.ShopUrl,
                color          = product.Color,
                available      = product.Available,
                season         = product.Season,
                seasonYear     = product.SeasonYear,
                activationDate = product.ActivationDate
            };

            productDto.genders = product.ProductGenders.Select(x => x.Gender.Name).ToArray();

            var dtoUnits = new List <Dto.Unit>();

            foreach (var unit in product.Units)
            {
                var dtoUnit = new Dto.Unit
                {
                    available = unit.Available,
                    id        = unit.Id,
                    price     = new Price
                    {
                        currency  = unit.Price.Currency,
                        value     = unit.Price.Value,
                        formatted = unit.Price.Formatted
                    },
                    originalPrice = new Price
                    {
                        currency  = unit.OriginalPrice.Currency,
                        value     = unit.OriginalPrice.Value,
                        formatted = unit.OriginalPrice.Formatted
                    },
                    size  = unit.Size,
                    stock = unit.Stock
                };
                dtoUnits.Add(dtoUnit);
            }

            Dto.Brand brandDto = new Dto.Brand
            {
                key          = product.Brand.Key,
                name         = product.Brand.Name,
                logoUrl      = product.Brand.LogoUrl,
                logoLargeUrl = product.Brand.LogoLargeUrl,
                brandFamily  = new Brandfamily
                {
                    key     = product.Brand.BrandFamily.Key,
                    name    = product.Brand.BrandFamily.Name,
                    shopUrl = product.Brand.BrandFamily.ShopUrl
                },
                shopUrl = product.Brand.ShopUrl
            };

            productDto.units = dtoUnits.ToArray();
            productDto.brand = brandDto;
            return(productDto);
        }
Example #5
0
 public async Task <Result <bool> > Update(Dto.Product product)
 {
     return(await this.repository.Update(product));
 }
Example #6
0
 public async Task <Result <bool> > Insert(Dto.Product product)
 {
     return(await this.repository.Insert(product));
 }