public int UpdateProductQuantityByProductId(int productId, int quantity)
        {
            if (productId >= 0 || quantity == 0)
            {
                throw new ArgumentException("Đã Có Lỗi Xảy Ra!");
            }

            var keyName = new[]
            {
                "Id"
            };

            var parameters = new
            {
                Stock = quantity,
                Id    = productId
            };

            var rowAffected = DapperRepositoryUtil.UpdateRecordInTable(PRODUCT_TABLE_NAME, DbUtilities.GetConnString(SQL_CONNECTION_STRING), parameters, keyName);

            if (rowAffected < 1)
            {
                throw new ArgumentException("Đã Có Lỗi Xảy Ra!");
            }

            return(rowAffected);
        }
Beispiel #2
0
        public int UpdateCategoryById(Category entity)
        {
            if (string.IsNullOrEmpty(entity.Name))
            {
                throw new ArgumentNullException(nameof(entity.Name));
            }

            if (string.IsNullOrEmpty(entity.Code))
            {
                throw new ArgumentNullException(nameof(entity.Code));
            }

            var parameters = new
            {
                entity.Code,
                entity.Name,
            };

            var rowAffected = DapperRepositoryUtil.UpdateRecordInTable(TABLE_NAME, DbUtilities.GetConnString(SQL_CONNECTION_STRING), "Id", entity.Id, parameters, true);

            if (rowAffected < 1)
            {
                throw new ArgumentException("Đã Có Lỗi Xảy Ra!");
            }

            return(rowAffected);
        }
        public int DeleteProductsByUniqueIds(IEnumerable <int> productUniqueIds)
        {
            if (!productUniqueIds.Any())
            {
                throw new ArgumentNullException(nameof(productUniqueIds));
            }

            var parameter = new
            {
                ProductCode  = string.Empty,
                IsActive     = false,
                IsDeleted    = true,
                ModifiedDate = DateTime.Now,
                ModifiedBy   = Thread.CurrentPrincipal.Identity.Name
            };

            var rowAffected = 0;

            foreach (var productUniqueId in productUniqueIds)
            {
                rowAffected = +DapperRepositoryUtil.UpdateRecordInTable(PRODUCT_TABLE_NAME, DbUtilities.GetConnString(SQL_CONNECTION_STRING), "Id", productUniqueId, parameter);
            }

            if (rowAffected < 1)
            {
                throw new ArgumentException("Đã Có Lỗi Xảy Ra!");
            }

            return(rowAffected);
        }
Beispiel #4
0
        public int AddNewCategory(Category entity)
        {
            if (string.IsNullOrEmpty(entity.Name))
            {
                throw new ArgumentNullException(nameof(entity.Name));
            }

            if (string.IsNullOrEmpty(entity.Code))
            {
                throw new ArgumentNullException(nameof(entity.Code));
            }

            var keyName = new[]
            {
                "Name"
            };
            var parameters = new
            {
                entity.Code,
                entity.Name,
            };

            var rowAffected = DapperRepositoryUtil.InsertIfNotExist(TABLE_NAME, DbUtilities.GetConnString(SQL_CONNECTION_STRING), parameters, keyName);

            if (rowAffected < 1)
            {
                throw new ArgumentException("Đã Có Lỗi Xảy Ra!");
            }

            return(rowAffected);
        }
Beispiel #5
0
        public int AddImportLog(ImportLog entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("Invalid data!");
            }

            var parameter = new
            {
                entity.UserId,
                entity.ProductId,
                entity.SupplierId,
                entity.Quantity,
                entity.TotalCost,
                entity.TotalBaseCost,
                entity.ForeignCurrency,
                entity.Created
            };

            var keyNames = new[]
            {
                "Created"
            };

            var result = DapperRepositoryUtil.InsertIfNotExist(TABLE_NAME, DbUtilities.GetConnString(SQL_CONNECTION_STRING), parameter, keyNames);

            return(result);
        }
Beispiel #6
0
        public int UpdateSupplier(Supplier model)
        {
            if (string.IsNullOrEmpty(model.CompanyName))
            {
                throw new ArgumentNullException(nameof(model.CompanyName));
            }

            var parameter = new
            {
                model.CompanyName,
                model.Address,
                model.DirectorName,
                model.Email,
                model.Fax,
                model.HomeTown,
                model.IsActive,
                model.Note,
                model.Phone,
                model.TaxCode
            };

            var rowAffected = DapperRepositoryUtil.UpdateRecordInTable(SUPPLIER_TABLE_NAME, DbUtilities.GetConnString(SQL_CONNECTION_STRING), "Id", model.Id, parameter, true);

            if (rowAffected < 1)
            {
                throw new ArgumentException("Đã Có Lỗi Xảy Ra!");
            }

            return(rowAffected);
        }
Beispiel #7
0
        public int AddNewSupplier(Supplier model)
        {
            if (string.IsNullOrEmpty(model.CompanyName))
            {
                throw new ArgumentNullException(nameof(model.CompanyName));
            }

            var keyName = new[]
            {
                "CompanyName"
            };

            var parameter = new
            {
                model.CompanyName,
                model.Address,
                model.DirectorName,
                model.Email,
                model.Fax,
                model.HomeTown,
                model.Note,
                model.Phone,
                model.TaxCode
            };

            var rowAffected = DapperRepositoryUtil.InsertIfNotExist(SUPPLIER_TABLE_NAME, DbUtilities.GetConnString(SQL_CONNECTION_STRING), parameter, keyName);

            if (rowAffected < 1)
            {
                throw new ArgumentException("Đã Có Lỗi Xảy Ra!");
            }

            return(rowAffected);
        }
        public int UpdateProductByUniqueId(Product entity)
        {
            if (string.IsNullOrEmpty(entity.Name))
            {
                throw new ArgumentNullException(nameof(entity.Name));
            }

            var keyName = new[]
            {
                "Id"
            };

            var parameters = new
            {
                entity.BaseCost,
                entity.CategoryId,
                entity.ExpiredDate,
                entity.IssuedDate,
                entity.IsActive,
                entity.Name,
                entity.ProductCode,
                entity.Status,
                entity.Stock,
                entity.SupplierId,
                entity.Id
            };

            var rowAffected = DapperRepositoryUtil.UpdateRecordInTable(PRODUCT_TABLE_NAME, DbUtilities.GetConnString(SQL_CONNECTION_STRING), parameters, keyName);

            if (rowAffected < 1)
            {
                throw new ArgumentException("Đã Có Lỗi Xảy Ra!");
            }

            return(rowAffected);
        }
Beispiel #9
0
        public int DeleteSupplier(Supplier entity)
        {
            var parameter = new
            {
                IsDeleted = true,
                entity.Id,
                ModifiedDate = DateTime.Now,
                ModifiedBy   = Thread.CurrentPrincipal.Identity.Name
            };

            var keyName = new[]
            {
                "Id"
            };

            var rowAffected = DapperRepositoryUtil.UpdateRecordInTable(SUPPLIER_TABLE_NAME, DbUtilities.GetConnString(SQL_CONNECTION_STRING), parameter, keyName);

            if (rowAffected < 1)
            {
                throw new ArgumentException("Đã Có Lỗi Xảy Ra!");
            }

            return(rowAffected);
        }