public void Delete(int? id)
 {
     using (var ctx = new InventorySystemMaintenanceEntities())
     {
         if (id != null)
         {
             var item = ctx.Material.FirstOrDefault(P => P.Id == id);
             ctx.DeleteObject(item);
             ctx.SaveChanges();
         }
     }
 }
 public void Delete(int? id)
 {
     using (var ctx = new InventorySystemMaintenanceEntities())
     {
         if (id != null)
         {
             var item = ctx.Supplier.FirstOrDefault(P => P.Id == id);
             ctx.Entry(item).State = System.Data.EntityState.Deleted;
             ctx.SaveChanges();
         }
     }
 }
 public Material Insert(string materialCode, string name, string description
     , decimal? pricePerUnit, string attachment, DateTime? dateCreated
     , DateTime? dateModified, string createdBy, string modifiedBy)
 {
     using (var ctx = new InventorySystemMaintenanceEntities())
     {
         Material item = new Material();
         if (!String.IsNullOrEmpty(materialCode))
         {
             item.MaterialCode = materialCode;
         }
         if (!String.IsNullOrEmpty(name))
         {
             item.Name = name;
         }
         if (!String.IsNullOrEmpty(description))
         {
             item.Description = description;
         }
         if (pricePerUnit != null)
         {
             item.PricePerUnit = pricePerUnit;
         }
         if (!String.IsNullOrEmpty(attachment))
         {
             item.Attachment = attachment;
         }
         if (dateCreated != null)
         {
             item.DateCreated = dateCreated;
         }
         if (dateModified != null)
         {
             item.DateModified = dateModified;
         }
         if (!String.IsNullOrEmpty(createdBy))
         {
             item.CreatedBy = createdBy;
         }
         if (!String.IsNullOrEmpty(modifiedBy))
         {
             item.ModifiedBy = modifiedBy;
         }
         ctx.AddToMaterial(item);
         ctx.SaveChanges();
         return item;
     }
 }
        public void UpdateAttachment(int? id,string attachment)
        {
            using (var ctx = new InventorySystemMaintenanceEntities())
            {
                if (id != null)
                {
                    var item = ctx.Material.FirstOrDefault(P => P.Id == id.Value);
                    item.Attachment = attachment;
                    ctx.SaveChanges();
                }

            }
        }
 public Supplier Insert(string supplierCode, string name, string company
     , string phoneNo, string fax, string email, string address, string postcode
     , string state, string country, string website, DateTime? dateCreated
     , DateTime? dateModified, string createdBy, string modifiedBy, string remarks)
 {
     using (var ctx = new InventorySystemMaintenanceEntities())
     {
         Supplier item = new Supplier();
         if (!String.IsNullOrEmpty(supplierCode))
         {
             item.SupplierCode = supplierCode;
         }
         if (!String.IsNullOrEmpty(name))
         {
             item.Name = name;
         }
         if (!String.IsNullOrEmpty(company))
         {
             item.Company = company;
         }
         if (!String.IsNullOrEmpty(phoneNo))
         {
             item.PhoneNo = phoneNo;
         }
         if (!String.IsNullOrEmpty(fax))
         {
             item.Fax = fax;
         }
         if (!String.IsNullOrEmpty(email))
         {
             item.Email = email;
         }
         if (!String.IsNullOrEmpty(address))
         {
             item.Address = address;
         }
         if (!String.IsNullOrEmpty(postcode))
         {
             item.Postcode = postcode;
         }
         if (!String.IsNullOrEmpty(state))
         {
             item.State = state;
         }
         if (!String.IsNullOrEmpty(country))
         {
             item.Country = country;
         }
         if (!String.IsNullOrEmpty(website))
         {
             item.Website = website;
         }
         if (dateCreated != null)
         {
             item.DateCreated = dateCreated;
         }
         if (dateModified != null)
         {
             item.DateModified = dateModified;
         }
         if (!String.IsNullOrEmpty(createdBy))
         {
             item.CreatedBy = createdBy;
         }
         if (!String.IsNullOrEmpty(modifiedBy))
         {
             item.ModifiedBy = modifiedBy;
         }
         if (!String.IsNullOrEmpty(remarks))
         {
             item.Remarks = remarks;
         }
         ctx.Entry(item).State = System.Data.EntityState.Added;
         ctx.SaveChanges();
         return item;
     }
 }
 public Customer Update(int id, string customerCode, string name, string company
     , string phoneNo, string fax, string email, string address, string postcode
     , string state, string country, string website, DateTime? dateCreated
     , DateTime? dateModified, string createdBy, string modifiedBy, string remarks)
 {
     using (var ctx = new InventorySystemMaintenanceEntities())
     {
         Customer item = ctx.Customer.FirstOrDefault(P => P.Id == id);
         if (!String.IsNullOrEmpty(customerCode))
         {
             item.CustomerCode = customerCode;
         }
         if (!String.IsNullOrEmpty(name))
         {
             item.Name = name;
         }
         if (!String.IsNullOrEmpty(company))
         {
             item.Company = company;
         }
         if (!String.IsNullOrEmpty(phoneNo))
         {
             item.PhoneNo = phoneNo;
         }
         if (!String.IsNullOrEmpty(fax))
         {
             item.Fax = fax;
         }
         if (!String.IsNullOrEmpty(email))
         {
             item.Email = email;
         }
         if (!String.IsNullOrEmpty(address))
         {
             item.Address = address;
         }
         if (!String.IsNullOrEmpty(postcode))
         {
             item.Postcode = postcode;
         }
         if (!String.IsNullOrEmpty(state))
         {
             item.State = state;
         }
         if (!String.IsNullOrEmpty(country))
         {
             item.Country = country;
         }
         if (!String.IsNullOrEmpty(website))
         {
             item.Website = website;
         }
         if (dateCreated != null)
         {
             item.DateCreated = dateCreated;
         }
         if (dateModified != null)
         {
             item.DateModified = dateModified;
         }
         if (!String.IsNullOrEmpty(createdBy))
         {
             item.CreatedBy = createdBy;
         }
         if (!String.IsNullOrEmpty(modifiedBy))
         {
             item.ModifiedBy = modifiedBy;
         }
         if (!String.IsNullOrEmpty(remarks))
         {
             item.Remarks = remarks;
         }
         ctx.SaveChanges();
         return item;
     }
 }
 public Pattern Insert(int? supplierId, string patternCode, string patternMaker,
     decimal? price, decimal? outerDiameter, decimal? innerDiameter, decimal? height,
     decimal? width, decimal? length, string modificationRemarks, DateTime? dateCreated,
     DateTime? dateModified, string createdBy, string modifiedBy, string remarks)
 {
     using (var ctx = new InventorySystemMaintenanceEntities())
     {
         Pattern item = new Pattern();
         if (supplierId != null)
         {
             item.SupplierId = supplierId;
         }
         if (!String.IsNullOrEmpty(patternCode))
         {
             item.PatternCode = patternCode;
         }
         if (!String.IsNullOrEmpty(patternMaker))
         {
             item.PatternMaker = patternMaker;
         }
         if (outerDiameter != null)
         {
             item.OuterDiameter = outerDiameter;
         }
         if (innerDiameter != null)
         {
             item.InnerDiameter = innerDiameter;
         }
         if (height != null)
         {
             item.Height = height;
         }
         if (width != null)
         {
             item.Width = width;
         }
         if (length != null)
         {
             item.Length = length;
         }
         if (!String.IsNullOrEmpty(modificationRemarks))
         {
             item.ModificationRemarks = modificationRemarks;
         }
         if (dateCreated != null)
         {
             item.DateCreated = dateCreated;
         }
         if (dateModified != null)
         {
             item.DateModified = dateModified;
         }
         if (!String.IsNullOrEmpty(createdBy))
         {
             item.CreatedBy = createdBy;
         }
         if (!String.IsNullOrEmpty(modifiedBy))
         {
             item.ModifiedBy = modifiedBy;
         }
         if (!String.IsNullOrEmpty(remarks))
         {
             item.Remarks = remarks;
         }
         ctx.AddToPattern(item);
         ctx.SaveChanges();
         return item;
     }
 }
 public Product Update(int id, string productCode, int? productGroupId, int? customerId,
     int? supplierId, string name, string description, decimal? weight, string image,
     decimal? outerDiameter, decimal? innerDiameter, decimal? height, decimal? width,
     decimal? length, DateTime? dateCreated, DateTime? dateModified, string createdBy,
     string modifiedBy, string remarks)
 {
     using (var ctx = new InventorySystemMaintenanceEntities())
     {
         Product item = ctx.Product.FirstOrDefault(P => P.Id == id);
         if (!String.IsNullOrEmpty(productCode))
         {
             item.ProductCode = productCode;
         }
         if (CheckNull(productGroupId))
         {
             item.ProductGroupId = productGroupId;
         }
         if (CheckNull(customerId))
         {
             item.CustomerId = customerId;
         }
         if (CheckNull(supplierId))
         {
             item.SupplierId = supplierId;
         }
         if (!String.IsNullOrEmpty(name))
         {
             item.Name = name;
         }
         if (!String.IsNullOrEmpty(description))
         {
             item.Description = description;
         }
         if (CheckNull(weight))
         {
             item.Weight = weight;
         }
         if (!String.IsNullOrEmpty(image))
         {
             item.Image = image;
         }
         if (CheckNull(outerDiameter))
         {
             item.OuterDiameter = outerDiameter;
         }
         if (CheckNull(innerDiameter))
         {
             item.InnerDiameter = innerDiameter;
         }
         if (CheckNull(height))
         {
             item.Height = height;
         }
         if (CheckNull(width))
         {
             item.Width = width;
         }
         if (CheckNull(length))
         {
             item.Length = length;
         }
         if (CheckNull(dateCreated))
         {
             item.DateCreated = dateCreated;
         }
         if (CheckNull(dateModified))
         {
             item.DateModified = dateModified;
         }
         if (!String.IsNullOrEmpty(createdBy))
         {
             item.CreatedBy = createdBy;
         }
         if (!String.IsNullOrEmpty(modifiedBy))
         {
             item.ModifiedBy = modifiedBy;
         }
         if (!String.IsNullOrEmpty(remarks))
         {
             item.Remarks = remarks;
         }
         ctx.SaveChanges();
         return item;
     }
 }