Ejemplo n.º 1
0
 public LocalizedProductByCategoryBM(BarcodeBM barcode, string languageCode, string localizedName, BriefManufacturerBM manufacturer)
 {
     Barcode       = barcode;
     LanguageCode  = languageCode;
     LocalizedName = localizedName;
     Manufacturer  = manufacturer;
 }
Ejemplo n.º 2
0
 public ProductBM(BarcodeBM barcode, long?manufacturerId, long?categoryId, IReadOnlyDictionary <string, string> productName)
 {
     Barcode        = barcode;
     ManufacturerId = manufacturerId;
     CategoryId     = categoryId;
     ProductName    = productName;
 }
 public CreateProductRequestBM(BarcodeBM barcode, ManufacturerIdBM manufacturerId, CategoryIdBM categoryId, IReadOnlyDictionary <string, string> name)
 {
     Barcode        = barcode ?? throw new ArgumentNullException(nameof(barcode));
     ManufacturerId = manufacturerId;
     CategoryId     = categoryId;
     Name           = name ?? throw new ArgumentNullException(nameof(name));
 }
Ejemplo n.º 4
0
 public UpdateProductRequestBM(BarcodeBM barcode, ManufacturerIdBM newManufacturerId, CategoryIdBM newCategoryId, IReadOnlyDictionary <string, string> productName)
 {
     Barcode           = barcode;
     NewManufacturerId = newManufacturerId;
     NewCategoryId     = newCategoryId;
     ProductName       = productName;
 }
        public async Task <LocalizedProductBM> GetLocalizedProductAsync(BarcodeBM barcode, string languageCode)
        {
            var query = from product in dbContext.Product
                        join productName in dbContext.ProductName on product.Barcode equals productName.Barcode

                        join selected_category in dbContext.Category on product.CategoryId equals selected_category.Id into product_category_join

                        from category in product_category_join.DefaultIfEmpty()
                        join selected_categoryName in dbContext.CategoryName on category.Id equals selected_categoryName.CategoryId into category_categoryname_join

                        from categoryName in category_categoryname_join.DefaultIfEmpty()
                        join selected_manufacturer in dbContext.Manufacturer on product.ManufacturerId equals selected_manufacturer.Id into product_manufacturer_join

                        from manufacturer in product_manufacturer_join.DefaultIfEmpty()

                        where
                        product.Barcode == barcode.Value &&
                        productName.LanguageCode == languageCode &&
                        (categoryName == null ? true : categoryName.LanguageCode == languageCode)

                        select new LocalizedProductBM(
                //product
                barcode,
                languageCode,
                productName.LocalizedName,

                //category
                category == null ? null : new LocalizedCategoryBM(
                    (long?)category.Id ?? 0,
                    categoryName.LanguageCode,
                    categoryName.LocalizedName,
                    category.ParentId
                    ),

                //manufacturer
                manufacturer == null ? null : new BriefManufacturerBM(
                    (long?)manufacturer.Id ?? 0,
                    manufacturer.Name,
                    new ManufacturerLocationBM(
                        manufacturer.LocationCountrycode,
                        manufacturer.LocationAddress
                        ),
                    manufacturer.WebsiteUrl == null ? null : new Uri(manufacturer.WebsiteUrl)
                    )
                );

            try {
                return(await query.SingleAsync());
            }
            catch (Exception) {
                return(null);
            }
        }
        public Task <ProductBM> GetProductAsync(BarcodeBM barcode)
        {
            var query = from product in dbContext.Product.Include(x => x.ProductName)
                        where product.Barcode == barcode.Value
                        select new ProductBM(
                product.Barcode,
                product.ManufacturerId,
                product.CategoryId,
                product.ProductName.Select(x => new { Key = x.LanguageCode, Value = x.LocalizedName }).ToDictionary(x => x.Key, x => x.Value)
                );

            return(query.SingleOrDefaultAsync());
        }
        public async Task <EmptyResultBM <DeleteProductExplanation> > DeleteProductAsync(BarcodeBM barcode)
        {
            try {
                Product productToDelete = await dbContext.Product.SingleAsync(x => x.Barcode == barcode.Value);

                dbContext.ProductName.RemoveRange(
                    dbContext.ProductName.Where(x => x.Barcode == barcode.Value)
                    );

                dbContext.Product.Remove(productToDelete);

                await dbContext.SaveChangesAsync();
            }
            catch (InvalidOperationException) {
                return(new EmptyResultBM <DeleteProductExplanation>(DeleteProductExplanation.ProductNotExists));
            }
            catch (Exception) {
                return(new EmptyResultBM <DeleteProductExplanation>(DeleteProductExplanation.DatabaseError));
            }

            return(new EmptyResultBM <DeleteProductExplanation>());
        }
 public Task <bool> ProductExistsWithBarcodeAsync(BarcodeBM barcode)
 {
     return(dbContext.Product.AnyAsync(x => x.Barcode == barcode.Value));
 }
 public Task <LocalizedProductBM> GetProductAsync(BarcodeBM barcode, string languageCode)
 {
     return(productDataManager.GetLocalizedProductAsync(barcode, languageCode));
 }
Ejemplo n.º 10
0
 public Task <EmptyResultBM <DeleteProductExplanation> > DeleteProductAsync(BarcodeBM barcode)
 {
     return(productDataManager.DeleteProductAsync(barcode));
 }