示例#1
0
        public MaterialVendor Add(MaterialVendor materialVendor)
        {
            _context.Add(materialVendor);
            _context.SaveChanges();

            return(materialVendor);
        }
示例#2
0
        public int Update(MaterialVendor materialVendor)
        {
            _context.MaterialVendors.Update(materialVendor);
            _context.SaveChanges();

            return(materialVendor.MaterialVendorId);
        }
示例#3
0
 public void ValidateMaterial(MaterialVendor materialVendor, ref Error error)
 {
     if (materialVendor.VendorId == 0)
     {
         error.ErrorCode = ErrorCode.INVALID;
         error.Message   = "Please select a vendor";
     }
     else if (materialVendor.Cost <= 0)
     {
         error.ErrorCode = ErrorCode.INVALID;
         error.Message   = "Material costs must be greater than 0";
     }
     //New Material Check
     else if (materialVendor.Material.MaterialId == 0)
     {
         if (string.IsNullOrEmpty(materialVendor.Material.Name))
         {
             error.ErrorCode = ErrorCode.INVALID;
             error.Message   = $"Please provide a name for the new material {materialVendor.Material.Name}";
         }
         else if (string.IsNullOrEmpty(materialVendor.Material.Unit))
         {
             error.ErrorCode = ErrorCode.INVALID;
             error.Message   = $"Please provide the units for {materialVendor.Material.Name}";
         }
     }
 }
 public static MaterialVendorDetails MapFromObject(MaterialVendor obj)
 {
     return(new MaterialVendorDetails()
     {
         MaterialVendorId = obj.MaterialVendorId,
         Cost = obj.Cost,
         Vendor = VendorListing.MapFromObject(obj.Vendor)
     });
 }
示例#5
0
        public List <MaterialVendor> GetMaterialsForVendor(int vendorId)
        {
            var materials = new List <MaterialVendor>();

            foreach (var material in _materialRepository.GetMaterialForVendor(vendorId))
            {
                materials.Add(MaterialVendor.MapFromEntity(material));
            }

            return(materials);
        }
示例#6
0
 public void UpdateMaterialVendor(MaterialVendor materialVendor)
 {
     if (materialVendor.MaterialVendorId > 0)
     {
         _materialRepository.Update(materialVendor.MapToEntity());
     }
     else
     {
         AddMaterial(materialVendor);
     }
 }
示例#7
0
 public static MaterialVendorListing MapFromObject(MaterialVendor obj)
 {
     return(new MaterialVendorListing()
     {
         MaterialId = obj.Material.MaterialId,
         MaterialVendorId = obj.MaterialVendorId,
         Name = obj.Material.Name,
         Unit = obj.Material.Unit,
         Cost = obj.Cost,
         VendorId = obj.VendorId
     });
 }
示例#8
0
 public void AddMaterial(MaterialVendor materialVendor)
 {
     if (materialVendor.Material.MaterialId == 0)
     {
         var newMaterial = _materialRepository.Add(materialVendor.Material.MapToEntity());
         materialVendor.Material.MaterialId = newMaterial.MaterialId;
     }
     if (materialVendor.MaterialVendorId == 0)
     {
         _materialRepository.Add(materialVendor.MapToEntity());
     }
     else
     {
         _materialRepository.Update(materialVendor.MapToEntity());
     }
 }
示例#9
0
        public MaterialVendor MapToCore()
        {
            var materialVendor = new MaterialVendor()
            {
                MaterialVendorId = this.MaterialVendorId,
                VendorId         = this.VendorId,
                Cost             = this.Cost
            };

            materialVendor.Material = new Material()
            {
                MaterialId = this.MaterialId,
                Name       = this.Name,
                Unit       = this.Unit
            };

            return(materialVendor);
        }