internal Message AddSupplierDB(SupplierMain data)
        {
            msg = new Message();
            try
            {
                using (entity = new SpeedDatabaseEntities())
                {
                    SupplierMain sm = new SupplierMain();
                    sm.SupplierAddress     = data.SupplierAddress;
                    sm.SupplierName        = data.SupplierName;
                    sm.TotalPurchaseCost   = 0;
                    sm.TotalSupplierCredit = 0;
                    entity.SupplierMains.Add(sm);
                    entity.SaveChanges();

                    msg.success = true;
                    return(msg);
                }
            }
            catch (DataException ex)
            {
                msg.success = false;
                msg.message = ex.Message;
                return(msg);
            }
        }
 internal Message DeleteSupplierByID(int supplierId)
 {
     msg = new Message();
     try
     {
         using (entity = new SpeedDatabaseEntities())
         {
             if (entity.PurchaseMains.Any(s => s.SupplierID == supplierId))
             {
                 int purchaseid = entity.PurchaseMains.Where(s => s.SupplierID == supplierId).FirstOrDefault().PurchaseID;
                 msg.message = "Purchase has entries with selected Supplier. Please delete purchase with ID: " + purchaseid;
                 msg.success = false;
                 return(msg);
             }
             else
             {
                 entity.SupplierDetails.RemoveRange(entity.SupplierDetails.Where(s => s.SupplierID == supplierId));
                 entity.SupplierMains.Remove(entity.SupplierMains.Where(s => s.SupplierID == supplierId).FirstOrDefault());
                 entity.SaveChanges();
                 msg.success = true;
                 return(msg);
             }
         }
     }
     catch (DataException ex)
     {
         msg.message = ex.Message;
         msg.success = true;
         return(msg);
     }
 }
 internal Message UpdateProduct(Product data)
 {
     msg = new Message();
     try
     {
         using (entity = new SpeedDatabaseEntities())
         {
             Product obj = entity.Products.Where(s => s.ProductID == data.ProductID).FirstOrDefault();
             obj.CGST        = data.CGST;
             obj.HSN         = data.HSN;
             obj.IGST        = data.IGST;
             obj.ProductName = data.ProductName;
             obj.SGST        = data.SGST;
             entity.SaveChanges();
             msg.success = true;
             return(msg);
         }
     }
     catch (DataException ex)
     {
         msg.message = ex.Message;
         msg.success = false;
         return(msg);
     }
 }
 internal Message AddProductDB(ProductModel data)
 {
     msg = new Message();
     try
     {
         using (entity = new SpeedDatabaseEntities())
         {
             Product pr = new Product();
             pr.CGST        = data.cgst;
             pr.HSN         = data.hsn;
             pr.IGST        = data.igst;
             pr.ProductName = data.productName;
             pr.SGST        = data.sgst;
             entity.Products.Add(pr);
             entity.SaveChanges();
             msg.success = true;
             return(msg);
         }
     }
     catch (DataException ex)
     {
         msg.message = ex.Message;
         msg.success = false;
         return(msg);
     }
 }
Beispiel #5
0
        internal List <PurchaseMainModel> GetAllPurchase()
        {
            using (entity = new SpeedDatabaseEntities())
            {
                var result = (from pm in entity.PurchaseMains
                              join sm in entity.SupplierMains on pm.SupplierID equals sm.SupplierID
                              select new PurchaseMainModel
                {
                    pucrhaseDate = pm.PurchaseDate,
                    supplierId = (int)pm.SupplierID,
                    supplierName = sm.SupplierName,
                    totalAmountPaid = pm.TotalAmountPaid,
                    totalPurchaseCost = pm.TotalPurchaseAmount,
                    totalPurchaseCredit = pm.TotalPurchaseCredit,
                    purchaseId = pm.PurchaseID
                }).ToList();

                int i = 1;
                foreach (var item in result)
                {
                    item.slNo = i++;
                    item.date = item.pucrhaseDate.ToString("dd-MMM-yy");
                }
                return(result);
            }
        }
 internal SupplierMain GetSupplierByID(int supplierId)
 {
     using (entity = new SpeedDatabaseEntities())
     {
         SupplierMain data = entity.SupplierMains.Where(s => s.SupplierID == supplierId).FirstOrDefault();
         return(data);
     }
 }
 internal Product GetProductById(int productId)
 {
     using (entity = new SpeedDatabaseEntities())
     {
         Product data = entity.Products.Where(s => s.ProductID == productId).FirstOrDefault();
         return(data);
     }
 }
 internal Message deleteProductById(int productId)
 {
     msg = new Message();
     using (entity = new SpeedDatabaseEntities())
     {
         if (entity.PurchaseDetails.Any(s => s.ProductID == productId))
         {
             msg.message = "Product Exists in Purchase Entry. Please Delete Purchase";
             msg.success = false;
             return(msg);
         }
         else
         {
             Product obj = entity.Products.Where(s => s.ProductID == productId).FirstOrDefault();
             entity.Products.Remove(obj);
             entity.SaveChanges();
             msg.success = true;
             return(msg);
         }
     }
 }
        internal List <SupplierModel> GetAllSuppliers()
        {
            using (entity = new SpeedDatabaseEntities())
            {
                var result = (from supp in entity.SupplierMains
                              orderby supp.SupplierName
                              select new SupplierModel
                {
                    supplierId = supp.SupplierID,
                    supplierName = supp.SupplierName,
                    TotalPurchaseCost = (Int32)supp.TotalPurchaseCost,
                    TotalPurchaseCredit = supp.TotalSupplierCredit
                }).ToList();

                int i = 1;
                foreach (var item in result)
                {
                    item.slNo = i++;
                }
                return(result);
            }
        }
        internal Message UpdateSupplier(SupplierMain data)
        {
            msg = new Message();
            using (entity = new SpeedDatabaseEntities())
            {
                try
                {
                    SupplierMain sm = entity.SupplierMains.Where(s => s.SupplierID == data.SupplierID).FirstOrDefault();
                    sm.SupplierAddress = data.SupplierAddress;
                    sm.SupplierName    = data.SupplierName;
                    entity.SaveChanges();

                    msg.success = true;
                    return(msg);
                }
                catch (DataException ex)
                {
                    msg.success = false;
                    msg.message = ex.Message;
                    return(msg);
                }
            }
        }
 /// <summary>
 //Return All Product List
 /// </summary>
 /// <returns></returns>
 internal List <ProductModel> GetAllProducts()
 {
     using (entity = new SpeedDatabaseEntities())
     {
         var result = (from product in entity.Products
                       orderby product.ProductName
                       select new ProductModel
         {
             cgst = product.CGST,
             hsn = product.HSN,
             igst = product.IGST,
             productId = product.ProductID,
             productName = product.ProductName,
             sgst = product.SGST
         }).ToList();
         int i = 0;
         foreach (var item in result)
         {
             item.slNo = ++i;
         }
         return(result);
     }
 }