private void cmdSave_Click(object sender, EventArgs e)
        {
            if (txtManufacture.Text.Length > 0)
            {
                Manufacturer Manufacturer = new Manufacturer();

                //for Edit Data
                if (ManufacturerID.Length > 0 )
                {
                    Manufacturer.ManufacturerID = int.Parse(ManufacturerID);
                    Manufacturer.CreatedOn = Convert.ToDateTime(txtManufacture.Tag.ToString());
                }
                Manufacturer.Name = txtManufacture.Text.ToString();
                Manufacturer.IsActive = Convert.ToBoolean(chkIsActive.EditValue);
                Manufacturer.UpdatedOn = DateTime.Now;

                //for New Data
                if (ManufacturerID.Length < 0)
                {
                    Manufacturer.CreatedOn = DateTime.Now;
                }

                ProductService.SaveManufacturer(Manufacturer);

                grdManufacture.DataSource = ProductService.GetAllManufacturer(false);
            }
            else
            {
                MessageBox.Show("Please, fill the product name up!", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtManufacture.Focus();
            }
        }
        public void SaveManufacturer(Manufacturer manufacturer)
        {
            Manufacturer existingData = GetManufacturerByID(manufacturer.ManufacturerID);

            if (existingData == null)
            {
                manufacturer.CreatedOn = DateTime.Now;
                manufacturer.UpdatedOn = DateTime.Now;
                _context.Manufacturers.AddObject(manufacturer);
            }
            else
            {
                existingData.Name = manufacturer.Name;
                existingData.Description = manufacturer.Description;
                existingData.PictureID = manufacturer.PictureID;
                existingData.IsActive = manufacturer.IsActive;
                existingData.CreatedOn = existingData.CreatedOn;
                existingData.UpdatedOn = DateTime.Now;

                if (!_context.IsAttached(existingData))
                    _context.Manufacturers.Attach(existingData);
            }
            _context.SaveChanges();
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Manufacturers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToManufacturers(Manufacturer manufacturer)
 {
     base.AddObject("Manufacturers", manufacturer);
 }
 /// <summary>
 /// Create a new Manufacturer object.
 /// </summary>
 /// <param name="manufacturerID">Initial value of the ManufacturerID property.</param>
 public static Manufacturer CreateManufacturer(global::System.Int32 manufacturerID)
 {
     Manufacturer manufacturer = new Manufacturer();
     manufacturer.ManufacturerID = manufacturerID;
     return manufacturer;
 }
        /// <summary>
        /// Save Manufacturers use for both Insert and Update 
        /// </summary>
        /// <param name="Manufacturer">The manufacturer.</param>
        public bool SaveManufacturer(Manufacturer manufacturer)
        {
            Manufacturer existingData = new Manufacturer();

            existingData = GetManufacturerByName(manufacturer.Name);

            if (existingData != null && existingData.ManufacturerID != manufacturer.ManufacturerID)
            {
                if (existingData.ManufacturerID != 0)
                    return false;
            }

            existingData = GetManufacturerByID(manufacturer.ManufacturerID);

            if (existingData == null)
            {
                _context.Manufacturers.AddObject(manufacturer);
            }
            else
            {
                existingData.Name = manufacturer.Name;
                existingData.Description = manufacturer.Description;

                if (!_context.IsAttached(existingData))
                    _context.Manufacturers.Attach(existingData);
            }
            _context.SaveChanges();

            return true;
        }