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;
     }
 }
Пример #2
0
 protected void gvMaterials_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     int id = Convert.ToInt32(e.CommandArgument);
     Material item = new Material();
     item = items.FirstOrDefault(P => P.Id == id);
     if (e.CommandName == "Select")
     {
         iMaterial.ImageUrl = "~/images/materials/" + item.Attachment;
         hfId.Value = item.Id.ToString();
         txtMaterialCode.Text = item.MaterialCode;
         txtMaterialName.Text = item.Name;
         txtPricePerUnit.Text = item.PricePerUnit.ToString();
         txtDescription.Text = item.Description;
         hfAttachment.Value = item.Attachment;
         Helper.EnableControls(false, action);
     }
 }