Example #1
0
 public static Product MapToEditEntity(this ProductEditModels model, Product entity)
 {
     entity.ProductId       = model.ProductId;
     entity.ProductName     = model.ProductName;
     entity.SupplierId      = model.SupplierId;
     entity.CategoryId      = model.CategoryId;
     entity.QuantityPerUnit = model.QuantityPerUnit;
     entity.UnitPrice       = model.UnitPrice;
     entity.UnitsInStock    = model.UnitsInStock;
     entity.UnitsOnOrder    = model.UnitsOnOrder;
     entity.ReorderLevel    = model.ReorderLevel;
     entity.Discontinued    = model.Discontinued;
     return(entity);
 }
Example #2
0
 public static Product MapToEditEntity(this ProductEditModels model)
 {
     return(new Product
     {
         ProductId = model.ProductId,
         ProductName = model.ProductName,
         SupplierId = model.SupplierId,
         CategoryId = model.CategoryId,
         QuantityPerUnit = model.QuantityPerUnit,
         UnitPrice = model.UnitPrice,
         UnitsInStock = model.UnitsInStock,
         UnitsOnOrder = model.UnitsOnOrder,
         ReorderLevel = model.ReorderLevel,
         Discontinued = model.Discontinued
     });
 }
Example #3
0
        public ProductEditModels CreateProduct(ProductEditModels model, out string message)
        {
            var ship = _ProductRepository.getProduct(model.ProductId, model.ProductName);

            if (ship != null)
            {
                message = Constants.ProductIsExist;
                return(null);
            }
            var CreateProduct = _ProductRepository.Insert(model.MapToEditEntity());

            UnitOfwork.SaveChanges();
            if (CreateProduct == null)
            {
                message = Constants.CreateFail;
                return(null);
            }
            message = Constants.CreateSuccess;
            return(CreateProduct.MapToEditModel());
        }
Example #4
0
        public bool UpdateProduct(ProductEditModels model, out string message)
        {
            var ProductEntity = _ProductRepository.GetById(model.ProductId);

            if (ProductEntity != null)
            {
                var gr = _ProductRepository.getProduct(model.ProductId, model.ProductName);
                if (gr != null)
                {
                    message = Constants.ProductIsExist;
                    return(false);
                }
                ProductEntity = model.MapToEditEntity(ProductEntity);
                _ProductRepository.Update(ProductEntity);
                UnitOfwork.SaveChanges();
                message = Constants.UpdateSuccess;
                return(true);
            }
            message = Constants.UpdateFail;
            return(false);
        }