Example #1
0
        public Guid Add(Product entity)
        {
            if (string.IsNullOrEmpty(entity.Barcode))
                throw new ArgumentException("Product barcode cannot be empty!");

            if (string.IsNullOrEmpty(entity.Name))
                throw new ArgumentException("Product name cannot be empty!");

            using (OpenPOSDbEntities ctx = new OpenPOSDbEntities())
            {
                try
                {
                    entity.Status = true;
                    ctx.Products.AddObject(entity);
                    ctx.SaveChanges();
                    return entity.Id;
                }
                catch (Exception ex)
                {
                    LogService.Error("Error while adding product", ex);
                    throw new ArgumentException("Error while adding new product!");
                }
            }
        }
Example #2
0
 public void BeginEdit()
 {
     Backup = new Product();
     CopyValuesTo(this, Backup);
     HasChanges = false;
     _isEditMode = true;
 }
Example #3
0
        private void CopyValuesTo(Product src, Product dest)
        {
            if (src == null || dest == null) return;

            dest.Name = src.Name;
            dest.Barcode = src.Barcode;
            dest.MRP = src.MRP;
            dest.SellPrice = src.SellPrice;
            dest.BuyPrice = src.BuyPrice;
            dest.Discount = src.Discount;
            dest.SupplierId = src.SupplierId;
            dest.CategoryId = src.CategoryId;
            dest.TaxCategoryId = src.TaxCategoryId;
            dest.Stock = src.Stock;
            dest.MinStock = src.MinStock;
            dest.Status = src.Status;
            dest.Sold = src.Sold;
        }
Example #4
0
 public void EndEdit()
 {
     if (_isEditMode)
     {
         HasChanges = false;
         Backup = null;
     }
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Products EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProducts(Product product)
 {
     base.AddObject("Products", product);
 }
 /// <summary>
 /// Create a new Product object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="barcode">Initial value of the Barcode property.</param>
 /// <param name="mRP">Initial value of the MRP property.</param>
 /// <param name="sellPrice">Initial value of the SellPrice property.</param>
 /// <param name="buyPrice">Initial value of the BuyPrice property.</param>
 /// <param name="stock">Initial value of the Stock property.</param>
 /// <param name="minStock">Initial value of the MinStock property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 /// <param name="discount">Initial value of the Discount property.</param>
 public static Product CreateProduct(global::System.Guid id, global::System.String name, global::System.String barcode, global::System.Double mRP, global::System.Double sellPrice, global::System.Double buyPrice, global::System.Double stock, global::System.Double minStock, global::System.Boolean status, global::System.Double discount)
 {
     Product product = new Product();
     product.Id = id;
     product.Name = name;
     product.Barcode = barcode;
     product.MRP = mRP;
     product.SellPrice = sellPrice;
     product.BuyPrice = buyPrice;
     product.Stock = stock;
     product.MinStock = minStock;
     product.Status = status;
     product.Discount = discount;
     return product;
 }
Example #7
0
        public void Update(Product entity)
        {
            if (entity.Id.Equals(Guid.Empty))
                throw new ArgumentException("Product Id cannot be empty!");

            if (string.IsNullOrEmpty(entity.Barcode))
                throw new ArgumentException("Product barcode cannot be empty!");

            if (string.IsNullOrEmpty(entity.Name))
                throw new ArgumentException("Product name cannot be empty!");

            using (OpenPOSDbEntities ctx = new OpenPOSDbEntities())
            {
                try
                {

                    ctx.Products.Attach(entity);
                    ctx.ObjectStateManager.ChangeObjectState(entity, System.Data.EntityState.Modified);
                    ctx.Products.ApplyCurrentValues(entity);

                    ctx.SaveChanges();
                }
                catch (Exception ex)
                {
                    LogService.Error("Error while updating product", ex);
                    throw ex;
                }
            }
        }