Example #1
0
        public int DeleteFile(string file)
        {
            List <UploadedFile> dbFile = _serverContext.UploadedFiles.ToList();

            //foreach(UploadedFile f in dbFile)
            //{
            //    f.Path = Path.GetFileName(f.Path);
            //};


            List <UploadedFile> dbFileFiltered = dbFile.Where(x => Path.GetFileName(x.Path) == file).ToList();
            //_serverContext.UploadedFiles.Remove(dbFile);
            //_serverContext.SaveChanges();
            string fullPath = Path.Combine(_environment.WebRootPath, file);

            if (File.Exists(fullPath))
            {
                File.Delete(fullPath);
                //UploadedFile dbFile1 = _serverContext.UploadedFiles.Find(x => x.P )
                //_serverContext.UploadedFiles.Remove(dbFile1);
                //_serverContext.SaveChanges();
                if (dbFileFiltered.Count > 0)
                {
                    foreach (UploadedFile f in dbFileFiltered)
                    {
                        _serverContext.UploadedFiles.Remove(f);
                    }
                    _serverContext.SaveChanges();
                }
            }
            return(1);
        }
        public int Add(InventoryModel inventoryModel)
        {
            Inventory inventory = new Inventory
            {
                InventoryProductServiceName             = inventoryModel.Name,
                InventoryProductServiceType             = inventoryModel.Type,
                InventoryProductServiceCode             = inventoryModel.ProductServiceCode,
                InventoryProductDescription             = inventoryModel.Description,
                InventoryProductServiceIncomeAccountId  = inventoryModel.IncomeAccount.Value,
                InventoryProductServiceExpenseAccountId = inventoryModel.ExpenseAccount == null ? null : inventoryModel.ExpenseAccount.Value,
                InventoryProductServiceCreatedDate      = DateTime.Now,
            };

            _serverContext.Inventories.Add(inventory);
            _serverContext.SaveChanges();
            return(inventory.Id);
        }
 public int AddUser(User user)
 {
     if (_serverContext.Users.FirstOrDefault(e => e.Email.ToLower() == user.Email.ToLower()) != null)
     {
         return(-1);
     }
     _serverContext.Users.Add(user);
     _serverContext.SaveChanges();
     return(user.Id);
 }
 public int AddAccount(ChartOfAccount account)
 {
     _serverContext.ChartOfAccounts.Add(account);
     _serverContext.SaveChanges();
     return(1);
 }
Example #5
0
        int UpdatePurchase(PurchaseModel purchaseModel, bool addMode)
        {
            Purchase purchase = null;

            if (addMode)
            {
                purchase = new Purchase
                {
                    SubsidiaryLedgerAccountId = purchaseModel.Vendor.Value,
                    PurchaseModeOfPayment     = purchaseModel.ModeOfPayment,
                    ChartOfAccountId          = purchaseModel.ModeOfPayment == "PD" ? purchaseModel.ChartOfAccounts.Value : null,
                    PurchaseReferenceNo       = purchaseModel.ReferenceNo,
                    PurchaseAmount            = purchaseModel.Amount,
                    PurchaseDate        = purchaseModel.Date,
                    PurchaseDueDate     = purchaseModel.DueDate,
                    Description         = purchaseModel.Description,
                    PurchaseCreatedDate = DateTime.Now
                };
                _serverContext.Purchases.Add(purchase);
                _serverContext.SaveChanges();
            }
            else
            {
                purchase = _serverContext.Purchases.Find(purchaseModel.Id);
                purchase.SubsidiaryLedgerAccountId = purchaseModel.Vendor.Value;
                purchase.PurchaseModeOfPayment     = purchaseModel.ModeOfPayment;
                purchase.ChartOfAccountId          = purchaseModel.ModeOfPayment == "PD" ? purchaseModel.ChartOfAccounts.Value : null;
                purchase.PurchaseAmount            = purchaseModel.Amount;
                purchase.PurchaseReferenceNo       = purchaseModel.ReferenceNo;
                purchase.Description     = purchaseModel.Description;
                purchase.PurchaseDate    = purchaseModel.Date;
                purchase.PurchaseDueDate = purchaseModel.DueDate;
                _serverContext.SaveChanges();
            }
            if (!addMode)
            {
                foreach (var item in _serverContext.PurchaseDetails.Where(x => x.PurchaseId == purchaseModel.Id).ToList())
                {
                    PurchaseDetail purchaseDetail = new PurchaseDetail();
                    purchaseDetail = _serverContext.PurchaseDetails.Find(item.Id);
                    if (purchaseDetail != null)
                    {
                        _serverContext.PurchaseDetails.Remove(purchaseDetail);
                        _serverContext.SaveChanges();
                    }
                }
            }
            foreach (PurchaseItemModel item in purchaseModel.Items)
            {
                PurchaseDetail purchaseDetail = new PurchaseDetail();
                purchaseDetail.PurchaseId = purchase.Id;
                if (item.InventoryItem != null)
                {
                    purchaseDetail.PurchaseInventoryId = item.InventoryItem.Value;
                }
                purchaseDetail.ChartOfAccountId          = item.ChartOfAccountItem.Value;
                purchaseDetail.PurchaseTaxRateId         = item.TaxRateItem.Value;
                purchaseDetail.PurchaseDetailDescription = item.Description;
                purchaseDetail.PurchaseQuantity          = item.Quantity;
                purchaseDetail.PurchaseUnitPrice         = item.UnitPrice;
                _serverContext.PurchaseDetails.Add(purchaseDetail);
                _serverContext.SaveChanges();
            }

            if (!addMode)
            {
                var tempGl = _serverContext.GeneralLedgers.Where(x => x.PurchaseId == purchaseModel.Id).SingleOrDefault();
                _serverContext.GeneralLedgers.Remove(tempGl);
            }
            return(purchase.Id);
        }
Example #6
0
        public CustomerInvoiceModel EditSalesInvoice(CustomerInvoiceModel customerInvoiceModel)
        {
            _serverContext.Database.BeginTransaction();
            try
            {
                int ledgerMasterId = UpdateLedger(customerInvoiceModel, false);
                UpdateGeneralLedger(customerInvoiceModel, ledgerMasterId, ARTradeKey, SalesTaxKey);

                // collectively sum all qty per itemid inorder to check items availability
                var results = customerInvoiceModel.Items.GroupBy(x => x.SalesItem.Value).Select(g => new { Id = g.Key, Value = g.Sum(s => s.Qty) });
                foreach (var item in results)
                {
                    var Quantity = (from a in _serverContext.ViewInventoryBalances
                                    where a.Id == item.Id
                                    select new { balance = a.Balance }).FirstOrDefault();

                    if (Quantity == null)
                    {
                        continue;
                    }

                    if (Quantity.balance < item.Value)
                    {
                        _serverContext.InvoiceWithoutCosts.Add(new InvoiceWithoutCost
                        {
                            InvoiceWithoutCostInvoiceNo = customerInvoiceModel.InvoiceNo,
                            InvoiceWithoutCostDate      = customerInvoiceModel.Date
                        });
                        _serverContext.SaveChanges();
                        break;
                    }
                }
                _serverContext.Database.CommitTransaction();
            }
            catch (Exception ex)
            {
                _serverContext.Database.RollbackTransaction();
            }
            return(customerInvoiceModel);
        }
 public int AddAccount(Tracking account)
 {
     _serverContext.Trackings.Add(account);
     _serverContext.SaveChanges();
     return(account.Id);
 }
 public int AddAccount(SubsidiaryLedgerAccountName account)
 {
     _serverContext.SubsidiaryLedgerAccountNames.Add(account);
     _serverContext.SaveChanges();
     return(account.Id);
 }
 public int AddAccount(IncomeItem account)
 {
     _serverContext.IncomeItems.Add(account);
     _serverContext.SaveChanges();
     return(account.Id);
 }
Example #10
0
 public int AddAccount(TaxRate taxRate)
 {
     _serverContext.TaxRates.Add(taxRate);
     _serverContext.SaveChanges();
     return(taxRate.Id);
 }