コード例 #1
0
        public Product UpdateProduct(UpdateProductOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var product = SearchProduct(new SearchProductOptions
            {
                ProductId = options.ProductId
            }).SingleOrDefault();

            if (product != null)
            {
                product.Name        = options.Name;
                product.Description = options.Description;
            }

            context_.Add(product);
            if (context_.SaveChanges() > 0)
            {
                return(product);
            }

            return(null);
        }
コード例 #2
0
        public bool UpdateProduct(UpdateProductOptions options)
        {
            if (options == null)
            {
                return(false);
            }

            var query = context_
                        .Set <Product>()
                        .AsQueryable();

            var product = query.Where(c => c.ProductId == options.ProductId).SingleOrDefault();

            product = new Product()
            {
                ProductId   = options.ProductId,
                Name        = options.Name,
                Description = options.Description,
                Category    = options.Category,
                Price       = options.Price,
            };

            if (context_.SaveChanges() > 0)
            {
                return(true);
            }

            return(false);
        }
コード例 #3
0
        public Product UpdateProduct(UpdateProductOptions options)
        {
            if (options == null)
            {
                return(null);
            }

            var product = SearchProducts(new SearchProductOptions()
            {
                ProductId = options.ProductId
            }).SingleOrDefault();

            if (product == null)
            {
                return(null);
            }

            if (options.Name != null)
            {
                product.Name = options.Name;
            }
            if (options.Price != null)
            {
                product.Price = options.Price.Value;
            }
            if (options.Category != null)
            {
                product.Category = options.Category.Value;
            }

            context_.SaveChanges();

            return(product);
        }
コード例 #4
0
 public void UpdateProduct_Success()
 {
     var options = new UpdateProductOptions()
     {
         Description = "Lenovo",
         Price       = 600.00M
     };
     var sucess = psvc_.UpdateProductAsync("1111955", options);
 }
コード例 #5
0
ファイル: ProductService.cs プロジェクト: NikitasX/tinycrm
        /// <summary>
        ///
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public bool UpdateProduct(string productId,
                                  UpdateProductOptions options)
        {
            if (options == null)
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(productId))
            {
                return(false);
            }

            var product = GetProductById(productId);

            if (product == null)
            {
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(options.Name))
            {
                product.Name = options.Name;
            }

            if (options.Price > 0)
            {
                product.Price = options.Price;
            }

            if (options.Discount > 0)
            {
                product.Discount = options.Discount;
            }

            if (!string.IsNullOrWhiteSpace(options.Description))
            {
                product.Description = options.Description;
            }

            if (options.Category != ProductCategory.Invalid)
            {
                product.Category = options.Category;
            }

            context.Update(product);

            var success = false;

            try {
                success = context.SaveChanges() > 0;
            } catch (Exception e) {
                //
            }

            return(success);
        }
コード例 #6
0
        /// <summary>
        /// Find the product with id productId and updates it with the options
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public bool UpdateProduct(string productId, UpdateProductOptions options)
        {
            if (options == null)
            {
                return(false);
            }

            var product = GetProductById(productId);

            if (product == null)
            {
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(options.Description))
            {
                product.Description = options.Description;
            }

            if (!string.IsNullOrWhiteSpace(options.Name))
            {
                product.Name = options.Name;
            }

            if (options.Price != null)
            {
                if (options.Price <= 0)
                {
                    return(false);
                }
                else
                {
                    product.Price = options.Price;
                }
            }

            if (options.Discount != null)
            {
                if (options.Discount > 0M && options.Discount <= 100M)
                {
                    product.Discount = options.Discount;
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
コード例 #7
0
ファイル: ProductService.cs プロジェクト: AlexVossos/TinyCRM
        public Result <bool> UpdateProduct(string productId, UpdateProductOptions options)
        {
            var result = new Result <bool>();

            if (options == null)
            {
                result.ErrorCode = StatusCode.BadRequest;
                result.ErrorText = "Null options";

                return(result);
            }

            var product = GetProductById(productId).Data;

            if (product == null)
            {
                result.ErrorCode = StatusCode.NotFound;
                result.ErrorText = $"Product with id {productId} was not found";

                return(result);
            }

            if (options.Category != null)
            {
                product.Category = options.Category;
            }

            if (!string.IsNullOrWhiteSpace(options.Description))
            {
                product.Description = options.Description;
            }

            if (!string.IsNullOrWhiteSpace(options.Name))
            {
                product.Name = options.Name;
            }

            if (options.Price != null)
            {
                product.Price = options.Price;
            }

            if (context_.SaveChanges() == 0)
            {
                result.ErrorCode = StatusCode.InternalServerError;
                result.ErrorText = $"Customer could not be updated";
                return(result);
            }

            result.ErrorCode = StatusCode.OK;
            result.Data      = true;
            return(result);
        }
コード例 #8
0
        public Product UpdateProduct(UpdateProductOptions options)
        {
            if (options == null || options.ProductId == null)
            {
                return(null);
            }

            var checkprod = context_
                            .Set <Product>()
                            .Where(p => p.ProductId == options.ProductId)
                            .SingleOrDefault();

            if (checkprod == null) // not exists
            {
                return(null);
            }

            if (options.Name != null)
            {
                checkprod.Name = options.Name;
            }

            if (options.Description != null)
            {
                checkprod.Description = options.Description;
            }

            if (options.ProductId != null)
            {
                checkprod.ProductId = options.ProductId;
            }

            if (options.Price != null)
            {
                checkprod.Price = (decimal)options.Price;
            }

            if (options.Category != null)
            {
                checkprod.ProductCategory = (ProductCategory)options.Category;
            }

            if (context_.SaveChanges() > 0)
            {
                return(checkprod);
            }

            return(null);
        }
コード例 #9
0
        public bool UpdateProduct(Guid productId,
                                  UpdateProductOptions options)
        {
            if (options == null)
            {
                return(false);
            }

            var presult = GetProductById(productId);

            if (!presult.Success)
            {
                return(false);
            }
            var product = presult.Data;

            if (!string.IsNullOrWhiteSpace(options.Description))
            {
                product.Description = options.Description;
            }

            if (options.Price != null &&
                options.Price <= 0)
            {
                return(false);
            }

            if (options.Price != null)
            {
                if (options.Price <= 0)
                {
                    return(false);
                }
                else
                {
                    product.Price = options.Price.Value;
                }
            }

            if (options.Discount != null &&
                options.Discount < 0)
            {
                return(false);
            }

            return(true);
        }
コード例 #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <bool> UpdateProductAsync(string productId,
                                                    UpdateProductOptions options)
        {
            if (options == null)
            {
                return(false);
            }

            var product = await GetProductByIdAsync(productId);

            if (product == null)
            {
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(options.Description))
            {
                product.Data.Description = options.Description;
            }

            if (options.Price != null &&
                options.Price <= 0)
            {
                return(false);
            }

            if (options.Price != null)
            {
                if (options.Price <= 0)
                {
                    return(false);
                }
                else
                {
                    product.Data.Price = options.Price.Value;
                }
            }

            if (options.Discount != null &&
                options.Discount < 0)
            {
                return(false);
            }

            return(true);
        }
コード例 #11
0
ファイル: ProductService.cs プロジェクト: batsilas/TinyCRM
        public bool UpdateProduct(
            UpdateProductOptions options)
        {
            if (options == null) {
                return false;
            }

            var product = SearchProducts(
                new SearchProductOptions(){ 
                   ProductId = options.ProductId
            }).SingleOrDefault();

            if (!string.IsNullOrWhiteSpace(options.Description)) 
            {
                product.Description = options.Description;
            }

            if (!string.IsNullOrWhiteSpace(options.Name))
            {
                product.Name = options.Name;
            }

            if (options.Price != null)
            {
                product.Price = options.Price;
            }
                        
            if (options.Category != null)
            {
                product.Category = options.Category;
            }

            if (context.SaveChanges() > 0)
            {
                return true;
            }

            return false;
        }
コード例 #12
0
        public void UpdateProduct_Success()
        {
            var productId            = "SKU8";
            var updateProductOptions = new UpdateProductOptions()
            {
                Name        = "Pocophone F1",
                Price       = 399.88M,
                Discount    = 5,
                Description = "My New Phone",
                Category    = Core.Model.ProductCategory.Smartphones
            };

            Assert.True(psvc_.UpdateProduct(productId, updateProductOptions));

            var dProduct = psvc_.GetProductById(productId);

            Assert.Equal(updateProductOptions.Name, dProduct.Name);
            Assert.Equal(updateProductOptions.Price, dProduct.Price);
            Assert.Equal(updateProductOptions.Discount, dProduct.Discount);
            Assert.Equal(updateProductOptions.Description, dProduct.Description);
            Assert.Equal(updateProductOptions.Category, dProduct.Category);
        }
コード例 #13
0
        public Product UpdateProduct(UpdateProductOptions options)
        {
            if (options == null || options.ProductId == null)
            {
                return(null);
            }

            var product = context_
                          .Set <Product>()
                          .Where(x => x.ProductId == options.ProductId)
                          .SingleOrDefault();

            if (product == null)
            {
                return(null);
            }

            if (options.Category != null)
            {
                product.Category = (ProductCategory)options.Category;
            }

            if (options.Description != null)
            {
                product.Description = options.Description;
            }

            if (options.Name != null)
            {
                product.Name = options.Name;
            }

            if (options.Price != null)
            {
                product.Price = (decimal)options.Price;
            }

            return(context_.SaveChanges() > 0 ? product : null);
        }
コード例 #14
0
        public void UpdateProduct_Success()
        {
            var product = new AddProductOptions()
            {
                Name     = "product name",
                Price    = 1230M,
                Category = ProductCategory.Cameras,
                Id       = $"Test{CodeGenerator.CreateRandom()}"
            };

            Assert.True(products_.AddProduct(product));

            var updateproduct = new UpdateProductOptions()
            {
                Category    = ProductCategory.Televisions,
                Description = $"lalilulelo{CodeGenerator.CreateRandom()}",
                Discount    = 45M,
                Name        = $"New Name {CodeGenerator.CreateRandom()}",
                Price       = 45M
            };

            Assert.True(products_.UpdateProduct(product.Id, updateproduct));
        }
コード例 #15
0
 public bool UpdateProduct(Guid productId, UpdateProductOptions options)
 {
     return(prodServ.UpdateProduct(productId, options));
 }
コード例 #16
0
 public bool UpdateProduct(UpdateProductOptions options)
 {
     throw new NotImplementedException();
 }