Exemple #1
0
 /// <summary>
 /// Check if the project name already exists. If it does, then use the existing project instead of creating a new one
 /// The check is made at country programme level
 /// </summary>
 /// <param name="project"></param>
 /// <returns></returns>
 private void SaveProject(Project project)
 {
     List<Project> existingProjects;
     using (var context = new SCMSEntities())
     {
         existingProjects = context.Projects.Where(p => p.Name.Trim().Equals(project.Name.Trim(), StringComparison.CurrentCultureIgnoreCase) && p.CountryProgrammeId == project.CountryProgrammeId).ToList<Project>();
         if (existingProjects.Count > 0)
         {
             existingProjects[0].Name = project.Name;
             existingProjects[0].ShortName = project.ShortName;
             context.SaveChanges();
             project.Id = existingProjects[0].Id;
         }
         else
         {
             Project proj = new Project();
             proj.Name = project.Name;
             proj.ShortName = project.ShortName;
             proj.ProjectNumber = project.ProjectNumber;
             proj.CountryProgrammeId = project.CountryProgrammeId;
             proj.Id = project.Id = Guid.NewGuid();
             context.Projects.Add(proj);
             context.SaveChanges();
         }
     }
 }
Exemple #2
0
 public bool IsGRNVerified(GoodsReceivedNote GRNentity)
 {
     using (var context = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             foreach (GoodsReceivedNoteItem item in GRNentity.ItemColl)
             {
                 GoodsReceivedNoteItem grit = context.GoodsReceivedNoteItems.FirstOrDefault(p => p.Id == item.Id);
                 if (context.Inventories.Count(p => p.ItemId == grit.PurchaseOrderItem.Item.Id && p.WareHouseId == grit.GoodsReceivedNote.WareHouseId) > 0)
                 {
                     if (grit.PurchaseOrderItem.Item.ItemCategory.CategoryCode == "C")
                     {
                         Model.Inventory invt = context.Inventories.FirstOrDefault(p => p.ItemId == grit.PurchaseOrderItem.Item.Id && p.WareHouseId == grit.GoodsReceivedNote.WareHouseId);
                         invt.Quantity += (long)item.QuantityDelivered;
                         ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(invt, System.Data.EntityState.Modified);
                     }
                 }
                 else
                 {
                     long qty = 0;
                     if (grit.PurchaseOrderItem.Item.ItemCategory.CategoryCode == "C")
                     {
                         qty = (long)item.QuantityDelivered;
                     }
                     Model.Inventory newinvetoryEntity =
                         new Model.Inventory()
                     {
                         Id = Guid.NewGuid(), ItemId = grit.PurchaseOrderItem.Item.Id, Quantity = qty, CountryProgrammeId = GRNentity.CountryProgrammeId, WareHouseId = (Guid)grit.GoodsReceivedNote.WareHouseId
                     };
                     context.Inventories.Add(newinvetoryEntity);
                 }
                 Model.GoodsReceivedNoteItem grnitm = context.GoodsReceivedNoteItems.FirstOrDefault(p => p.Id == item.Id);
                 grnitm.QuantityDamaged = item.QuantityDamaged; grnitm.QuantityDelivered = item.QuantityDelivered;
                 ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(grnitm, System.Data.EntityState.Modified);
                 context.SaveChanges();
             }
             Model.GoodsReceivedNote grn = context.GoodsReceivedNotes.FirstOrDefault(p => p.Id == GRNentity.Id);
             grn.Verified            = true;
             grn.ApprovedOn          = DateTime.Now;
             grn.ReceptionApprovedBy = GRNentity.ReceptionApprovedBy;
             ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(grn, System.Data.EntityState.Modified);
             if (context.SaveChanges() > 0)
             {
                 scope.Complete(); return(true);
             }
             else
             {
                 scope.Dispose(); return(false);
             }
         }
     }
 }
Exemple #3
0
        public void UndoAuthorization(Model.OrderRequest or)
        {
            try
            {
                decimal?amount;
                decimal?currAmount; //Amount in ProjectBudget currency
                using (var context = new SCMSEntities())
                {
                    var orItems = context.OrderRequestItems.Where(i => i.OrderRequestId == or.Id).ToList();
                    foreach (var orItem in orItems)
                    {
                        amount     = orItem.EstimatedPrice;
                        currAmount = exchangeRateService.GetForeignCurrencyValue(orItem.ProjectBudget.BudgetCategory.ProjectDonor.Currency, orItem.OrderRequest.Currency, amount, (Guid)or.CountryProgrammeId);
                        orItem.ProjectBudget.TotalCommitted -= currAmount;

                        var budgetCommitmentList = context.BudgetCommitments.Where(b => b.OrderRequestItemId == orItem.Id).ToList();

                        foreach (var budgetCommitment in budgetCommitmentList)
                        {
                            context.BudgetCommitments.Remove(budgetCommitment);
                        }
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #4
0
        public void AuthorizeOrderRequest(Model.OrderRequest or)
        {
            try
            {
                decimal?amount;
                decimal?currAmount; //Amount in ProjectBudget currency
                using (var context = new SCMSEntities())
                {
                    var orItems = context.OrderRequestItems.Where(i => i.OrderRequestId == or.Id).ToList();
                    foreach (var orItem in orItems)
                    {
                        amount     = orItem.EstimatedPrice;
                        currAmount = exchangeRateService.GetForeignCurrencyValue(orItem.ProjectBudget.BudgetCategory.ProjectDonor.Currency, orItem.OrderRequest.Currency, amount, (Guid)or.CountryProgrammeId);
                        orItem.ProjectBudget.TotalCommitted += currAmount;

                        //Add to BudgetCommitment
                        var budgetCommitment = new BudgetCommitment();
                        budgetCommitment.Id = Guid.NewGuid();
                        budgetCommitment.OrderRequestItemId = orItem.Id;
                        budgetCommitment.AmountCommitted    = (decimal)currAmount;
                        budgetCommitment.DateCommitted      = DateTime.Now;
                        budgetCommitment.BudgetLineId       = orItem.ProjectBudget.Id;
                        context.BudgetCommitments.Add(budgetCommitment);
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #5
0
 public void RejectWRO(Guid wroId)
 {
     using (var context = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             try
             {
                 var wrnItems = context.WarehouseReleaseItems.Where(w => w.WarehouseReleaseId == wroId).ToList();
                 foreach (var wrnItem in wrnItems)
                 {
                     string itemCategory = context.Inventories.FirstOrDefault(p => p.Id == wrnItem.InventoryId).Item.ItemCategory.CategoryCode;
                     if (itemCategory.Equals("A"))
                     {
                         wrnItem.Quantity = 1;
                         Model.Asset ass = context.Assets.FirstOrDefault(p => p.Id == wrnItem.AssetId);
                         ass.IsReleased     = false;
                         ass.CurrentOwnerId = null;
                         ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(ass, System.Data.EntityState.Modified);
                     }
                     Model.Inventory inv = context.Inventories.First(p => p.Id == wrnItem.InventoryId);
                     inv.Quantity += (Int64)wrnItem.Quantity;
                     ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(inv, System.Data.EntityState.Modified);
                 }
                 context.SaveChanges();
                 SessionData.CurrentSession.ReleaseOrderList     = null;
                 SessionData.CurrentSession.ReleaseOrderItemList = null;
                 SessionData.CurrentSession.AssetList            = null;
                 SessionData.CurrentSession.InventoryList        = null;
                 scope.Complete();
             }
             catch (Exception ex) { scope.Dispose(); throw ex; }
         }
     }
 }
Exemple #6
0
 public bool IsWRNItemDeleted(Guid wrnItemId)
 {
     using (var context = new SCMSEntities())
     {
         Model.WarehouseReleaseItem wrnitm = context.WarehouseReleaseItems.FirstOrDefault(p => p.Id == wrnItemId);
         string itemCategory = context.Inventories.FirstOrDefault(p => p.Id == wrnitm.InventoryId).Item.ItemCategory.CategoryCode;
         if (itemCategory.Equals("A"))
         {
             wrnitm.Quantity = 1;
             Model.Asset ass = context.Assets.FirstOrDefault(p => p.Id == wrnitm.AssetId);
             ass.IsReleased     = false;
             ass.CurrentOwnerId = null;
             ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(ass, System.Data.EntityState.Modified);
         }
         Model.Inventory inv = context.Inventories.First(p => p.Id == wrnitm.InventoryId);
         inv.Quantity += (Int64)wrnitm.Quantity;
         ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(inv, System.Data.EntityState.Modified);
         context.WarehouseReleaseItems.Remove(wrnitm);
         int affectedColumns = context.SaveChanges();
         SessionData.CurrentSession.ReleaseOrderList     = null;
         SessionData.CurrentSession.ReleaseOrderItemList = null;
         SessionData.CurrentSession.AssetList            = null;
         SessionData.CurrentSession.InventoryList        = null;
         return(affectedColumns > 0 ? true : false);
     }
 }
Exemple #7
0
 public bool IsROrderDeleted(Guid ROId)
 {
     using (var context = new SCMSEntities())
     {
         var RO = context.WarehouseReleases.FirstOrDefault(p => p.Id == ROId);
         foreach (var item in RO.WarehouseReleaseItems)
         {
             string itemCategory = context.Inventories.FirstOrDefault(p => p.Id == item.InventoryId).Item.ItemCategory.CategoryCode;
             if (itemCategory.Equals("A"))
             {
                 item.Quantity = 1;
                 Model.Asset ass = context.Assets.FirstOrDefault(p => p.Id == item.AssetId);
                 ass.IsReleased     = false;
                 ass.CurrentOwnerId = null;
                 ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(ass, System.Data.EntityState.Modified);
             }
             Model.Inventory inv = context.Inventories.First(p => p.Id == item.InventoryId);
             inv.Quantity += (Int64)item.Quantity;
             ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(inv, System.Data.EntityState.Modified);
         }
         context.WarehouseReleases.Remove(RO);
         int affectedRecords = context.SaveChanges();
         SessionData.CurrentSession.ReleaseOrderList     = null;
         SessionData.CurrentSession.ReleaseOrderItemList = null;
         SessionData.CurrentSession.AssetList            = null;
         SessionData.CurrentSession.InventoryList        = null;
         return(affectedRecords > 0 ? true : false);
     }
 }
Exemple #8
0
 public bool SaveProcurementPlan(Model.ProcurementPlan pp)
 {
     ClearPPSessionData();
     using (var context = new SCMSEntities())
     {
         if (pp.Id.Equals(Guid.Empty))
         {
             var ppEntity = context.ProcurementPlans.FirstOrDefault(p => p.ProjectDonorId == pp.ProjectDonorId);
             var pd       = context.ProjectDonors.FirstOrDefault(p => p.Id == pp.ProjectDonorId);
             pp.RefNumber = "PP/DRC/" + pd.Project.CountryProgramme.Country.ShortName + "/" + pd.ProjectNumber;
             if (ppEntity != null)
             {
                 ppEntity.PreparedBy        = pp.PreparedBy;
                 ppEntity.PreparedOn        = pp.PreparedOn;
                 ppEntity.PreparingOfficeId = pp.PreparingOfficeId;
                 //let the object reference point to the existing entity from the db
                 pp.Id = ppEntity.Id;
             }
             else
             {
                 pp.Id = Guid.NewGuid();
                 context.ProcurementPlans.Add(pp);
             }
         }
         else
         {
             var existing = context.ProcurementPlans.FirstOrDefault(p => p.Id == pp.Id);
             context.Entry(existing).CurrentValues.SetValues(pp);
         }
         return(context.SaveChanges() > 0);
     }
 }
Exemple #9
0
 public bool SaveRequest4Payment(Model.PaymentRequest entity, EntityCollection <PaymentRequestBudgetLine> collection)
 {
     using (var context = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             try
             {
                 context.PaymentRequests.Add(entity);
                 //if (context.SaveChanges() > 0)
                 //{
                 foreach (PaymentRequestBudgetLine item in collection)
                 {
                     context.PaymentRequestBudgetLines.Add(item);
                     if (!(context.SaveChanges() > 0))
                     {
                         scope.Complete(); return(false);
                     }
                 }
                 //Send notification to Finance
                 notificationService.SendToAppropriateApprover(NotificationHelper.rfpCode, NotificationHelper.reviewCode, entity.Id);
                 scope.Complete();
                 return(true);
                 //}
                 //else { scope.Dispose(); return false; }
             }
             catch (Exception ex) { scope.Dispose(); throw new Exception(ex.Message); }
         }
     }
 }
Exemple #10
0
 public bool IsGIVEdited(Model.GoodsIssuedVoucher giventity)
 {
     using (var context = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             try
             {
                 var existing = context.GoodsIssuedVouchers.FirstOrDefault(p => p.Id == giventity.Id);
                 context.Entry(existing).CurrentValues.SetValues(giventity);
                 foreach (var item in giventity.ROItems)
                 {
                     GoodsIssuedVoucherItem mm;
                     var existingItem = mm = context.GoodsIssuedVoucherItems.FirstOrDefault(p => p.Id == item.GIVItemId);
                     mm.Remarks      = item.Remarks;
                     mm.QTYDelivered = item.QTYReceived;
                     context.Entry(existingItem).CurrentValues.SetValues(mm);
                 }
                 int affectedRecords = context.SaveChanges();
                 scope.Complete();
                 SessionData.CurrentSession.GIVList          = null;
                 SessionData.CurrentSession.ReleaseOrderList = null;
                 return(affectedRecords > 0);
             }
             catch (Exception ex) { scope.Dispose(); throw ex; }
         }
     }
 }
Exemple #11
0
 public void BackDateOR(Model.OrderRequest or)
 {
     using (var context = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             try
             {
                 //Get Current OR from DB
                 var currentOR = context.OrderRequests.FirstOrDefault(o => o.Id == or.Id);
                 //Initialize BackDate object
                 var backDate = new DocumentBackDating();
                 backDate.Id             = Guid.NewGuid();
                 backDate.BackDatedBy    = or.BackDatedBy;
                 backDate.BackDatedOn    = DateTime.Now;
                 backDate.NewDate        = or.OrderDate.Value;
                 backDate.OrderRequestId = or.Id;
                 backDate.PreviousDate   = currentOR.OrderDate.Value;
                 backDate.Reason         = or.BackDatingReason;
                 //Insert BackDate details into db
                 context.DocumentBackDatings.Add(backDate);
                 //Update date on OR in db
                 currentOR.OrderDate = or.OrderDate;
                 context.SaveChanges();
                 scope.Complete();
                 ClearORSessionData();
             }
             catch (Exception ex)
             {
                 scope.Dispose();
                 throw ex;
             }
         }
     }
 }
Exemple #12
0
 public void CreateBudgetLine(ProjectBudget bsl)
 {
     try
     {
         using (var context = new SCMSEntities())
         {
             var newBsl = new ProjectBudget();
             newBsl.Id               = Guid.NewGuid();
             newBsl.LineNumber       = bsl.LineNumber;
             newBsl.Description      = bsl.Description;
             newBsl.BudgetCategoryId = bsl.BudgetCategoryId;
             newBsl.TotalBudget      = bsl.TotalBudget;
             newBsl.TotalCommitted   = newBsl.TotalPosted = 0;
             //Save Overrun Adjustment Percentage
             var bc = context.BudgetCategories.IncludeProjectDonor().FirstOrDefault(b => b.Id == bsl.BudgetCategoryId.Value);
             if (!bsl.OverrunAdjustment.HasValue)
             {
                 newBsl.OverrunAdjustment = bc.ProjectDonor.OverrunAdjustment;
             }
             context.ProjectBudgets.Add(newBsl);
             context.SaveChanges();
             ClearProjectBudgetList();
         }
     }
     catch (Exception ex)
     {
     }
 }
Exemple #13
0
 public bool IsGIVItemAdded(Model.GoodsIssuedVoucher giventity)
 {
     using (var context = new SCMSEntities())
     {
         foreach (var item in giventity.ROItems)
         {
             if (item.IsRemoved)
             {
                 continue;
             }
             var givitem = new GoodsIssuedVoucherItem()
             {
                 Id                     = Guid.NewGuid(),
                 QTYDelivered           = item.QTYReceived,
                 GoodsIssuedVoucherId   = giventity.Id,
                 WarehouseReleaseItemId = item.ROItemId,
                 Remarks                = item.Remarks
             };
             context.GoodsIssuedVoucherItems.Add(givitem);
         }
         int affectedRecords = context.SaveChanges();
         SessionData.CurrentSession.GIVList          = null;
         SessionData.CurrentSession.ReleaseOrderList = null;
         return(affectedRecords > 0);
     }
 }
Exemple #14
0
 public bool SavePuchaseOrder(Model.PurchaseOrder entity)
 {
     using (var context = new SCMSEntities())
     {
         if (entity.Id.Equals(Guid.Empty))
         {
             entity.Id = Guid.NewGuid();
             context.PurchaseOrders.Add(entity);
         }
         else
         {
             var po = context.PurchaseOrders.FirstOrDefault(p => p.Id == entity.Id);
             po.CurrencyId         = entity.CurrencyId;
             po.DeliveryAddress    = entity.DeliveryAddress;
             po.LatestDeliveryDate = entity.LatestDeliveryDate;
             po.PaymentTermId      = entity.PaymentTermId;
             po.PODate             = entity.PODate;
             po.ProjectDonorId     = entity.ProjectDonorId;
             po.QuotationRef       = entity.QuotationRef;
             po.Remarks            = entity.Remarks;
             po.ShippingTermId     = entity.ShippingTermId;
             po.SupplierId         = entity.SupplierId;
             po.IsInternational    = entity.IsInternational;
         }
         ClearPOSessionData();
         return(context.SaveChanges() > 0);
     }
 }
Exemple #15
0
        public void UpdateProjectDonor(string projectDonorId, string projectNumber, DateTime startDate, DateTime endDate, Guid projectManagerId, string donorId, string currencyId, double? overrunAdjustment, ref string pdId)
        {
            if (ProjectNumberExits(projectNumber, projectDonorId))
            {
                pdId = null;
                return;
            }
            using (var context = new SCMSEntities())
            {
                var pd = context.ProjectDonors.FirstOrDefault(p => p.Id == new Guid(projectDonorId));
                pd.StartDate = startDate;
                pd.EndDate = endDate;
                pd.ProjectManagerId = projectManagerId;
                pd.DonorId = new Guid(donorId);
                pd.CurrencyId = new Guid(currencyId);
                pd.ProjectNumber = projectNumber;

                var blList = context.ProjectBudgets.Where(b => b.BudgetCategory.ProjectDonor.Id == pd.Id).ToList();
                foreach (var bl in blList)
                {
                    if (bl.OverrunAdjustment == pd.OverrunAdjustment)
                        bl.OverrunAdjustment = overrunAdjustment;
                }

                pd.OverrunAdjustment = overrunAdjustment;
                context.SaveChanges();
                pdId = projectDonorId;
            }
        }
Exemple #16
0
        private bool IsDepreciationComputed(SCMSEntities db, TransactionScope scope, Asset assetEntity)
        {
            //var firstdateinMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddMonths(-1);
            //var lastdateinMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddDays(-1);
            //float purchasePrc = (float)gitm.PurchaseOrderItem.UnitPrice
            Model.Depreciation          deprEntity = null;
            Model.GoodsReceivedNoteItem gitm = db.GoodsReceivedNoteItems.FirstOrDefault(p => p.Id == assetEntity.GoodsReceivedNoteItemId);
            float purchasePrc = (float)assetEntity.PurchaseValue, percentageDepr = (float)assetEntity.PercentageDepr, accAnnualDepr = 0;
            float annualDepr = 0, monthlyDepr, netbookValue = purchasePrc, accumulatedDepr = 0, salvagevalue = (float)assetEntity.SalvageValue;
            int   periodcount = 0, monthcount = 0, numberOfYears = 0;

            if (assetEntity.DepreciationType == "Reducing Balance")
            {
                monthlyDepr = ReducingBalance(db, assetEntity, ref deprEntity, percentageDepr, ref accAnnualDepr, ref annualDepr, ref netbookValue, ref accumulatedDepr, salvagevalue, ref periodcount, ref monthcount, ref numberOfYears);
            }
            else
            {
                monthlyDepr = StraightLine(db, assetEntity, ref deprEntity, purchasePrc, percentageDepr, ref accAnnualDepr, ref annualDepr, ref netbookValue, ref accumulatedDepr, salvagevalue, ref periodcount, ref monthcount);
            }

            if (!(db.SaveChanges() > 0))
            {
                scope.Dispose(); SessionData.CurrentSession.DepreciationList = null; return(false);
            }
            scope.Complete(); return(true);
        }
Exemple #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool AddItem(Item item)
        {
            bool isSaved = false;

            if (item.Id.Equals(Guid.Empty))
            {
                item.Id = Guid.NewGuid();
            }

            using (var context = new SCMSEntities())
            {
                UnitOfMeasure u = context.UnitOfMeasures.FirstOrDefault(p => p.Id == item.UnitOfMessureId);
                context.Items.Add(item);
                context.ItemPackages.Add(new ItemPackage()
                {
                    Id = Guid.NewGuid(), ItemId = item.Id, PackSize = 1, shortName = u.Code, Name = u.Description
                });
                if (context.SaveChanges() > 0)
                {
                    isSaved = true;
                    ClearItemSessionData();
                }
            }
            return(isSaved);
        }
Exemple #18
0
 public bool IsGIVSaved(Model.GoodsIssuedVoucher giventity)
 {
     using (var context = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             try
             {
                 context.GoodsIssuedVouchers.Add(giventity);
                 foreach (var item in giventity.ROItems)
                 {
                     if (item.IsRemoved)
                     {
                         continue;
                     }
                     var givitem = new GoodsIssuedVoucherItem()
                     {
                         Id                     = Guid.NewGuid(),
                         QTYDelivered           = item.QTYReceived,
                         GoodsIssuedVoucherId   = giventity.Id,
                         WarehouseReleaseItemId = item.ROItemId,
                         Remarks                = item.Remarks
                     };
                     context.GoodsIssuedVoucherItems.Add(givitem);
                 }
                 int affectedRecords = context.SaveChanges();
                 scope.Complete();
                 SessionData.CurrentSession.GIVList          = null;
                 SessionData.CurrentSession.ReleaseOrderList = null;
                 return(affectedRecords > 0);
             }
             catch (Exception ex) { scope.Dispose(); throw ex; }
         }
     }
 }
Exemple #19
0
 public void BackDatePO(Model.PurchaseOrder po)
 {
     using (var context = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             try
             {
                 //Get Current OR from DB
                 var currentPO = context.PurchaseOrders.FirstOrDefault(o => o.Id == po.Id);
                 //Initialize BackDate object
                 var backDate = new DocumentBackDating();
                 backDate.Id              = Guid.NewGuid();
                 backDate.BackDatedBy     = po.BackDatedBy;
                 backDate.BackDatedOn     = DateTime.Now;
                 backDate.NewDate         = po.PODate;
                 backDate.PurchaseOrderId = po.Id;
                 backDate.PreviousDate    = currentPO.PODate;
                 backDate.Reason          = po.BackDatingReason;
                 //Insert BackDate details into db
                 context.DocumentBackDatings.Add(backDate);
                 //Update date on OR in db
                 currentPO.PODate = po.PODate;
                 context.SaveChanges();
                 scope.Complete();
             }
             catch (Exception ex)
             {
                 scope.Dispose();
                 throw ex;
             }
         }
     }
 }
Exemple #20
0
 public void DeletePO(Guid PoId)
 {
     using (var context = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             try
             {
                 var po = context.PurchaseOrders.FirstOrDefault(p => p.Id == PoId);
                 po.PurchaseOrderItems.ToArray().ForEach(p => context.PurchaseOrderItems.Remove(p));
                 context.PurchaseOrders.Remove(po);
                 context.AttachedDocuments.Where(d => d.DocumentId == po.Id && d.DocumentType == NotificationHelper.poCode).ToArray().ForEach(d => context.AttachedDocuments.Remove(d));
                 if (context.SaveChanges() > 0)
                 {
                     scope.Complete();
                 }
                 else
                 {
                     scope.Dispose();
                 }
             }
             catch (Exception ex)
             {
                 scope.Dispose();
                 throw ex;
             }
             ClearPOSessionData();
             ClearORSessionData();
         }
     }
 }
Exemple #21
0
 public bool DeletePack(Guid pkgId)
 {
     using (var db = new SCMSEntities())
     {
         db.ItemPackages.Remove(db.ItemPackages.FirstOrDefault(p => p.Id == pkgId));
         return(db.SaveChanges() > 0 ? true : false);
     }
 }
Exemple #22
0
 public bool AddPackage(ItemPackage pack)
 {
     using (var db = new SCMSEntities())
     {
         db.ItemPackages.Add(pack);
         return(db.SaveChanges() > 0 ? true : false);
     }
 }
Exemple #23
0
 public bool SaveWB(Model.WayBill entity)
 {
     using (var db = new SCMSEntities())
     {
         db.WayBills.Add(entity);
         return(db.SaveChanges() > 0 ? true : false);
     }
 }
Exemple #24
0
 public bool IsFleetDetailsSaved(FleetDetail Entity)
 {
     using (var db = new SCMSEntities())
     {
         db.FleetDetails.Add(Entity);
         return db.SaveChanges() > 0 ? true : false;
     }
 }
Exemple #25
0
        public bool IsAssetRegistered(Model.Asset assetEntity)
        {
            using (var context = new SCMSEntities())
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        assetEntity.IsAssigned = false;
                        assetEntity.Id         = Guid.NewGuid();
                        //if (assetEntity.UseLifeSpan)
                        //    assetEntity.DepreciationType = "Straight Line";
                        context.Assets.Add(assetEntity);
                        if (context.Inventories.Count(p => p.ItemId == assetEntity.ItemId && p.WareHouseId == assetEntity.CurrentWareHouseId) > 0)
                        {
                            Model.Inventory invt = context.Inventories.FirstOrDefault(p => p.ItemId == assetEntity.ItemId && p.WareHouseId == assetEntity.CurrentWareHouseId);
                            invt.Quantity += 1;
                            ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(invt, System.Data.EntityState.Modified);
                        }
                        else
                        {
                            Model.Inventory newinvetoryEntity = new Model.Inventory()
                            {
                                Id = Guid.NewGuid(), ItemId = (Guid)assetEntity.ItemId, Quantity = 1, CountryProgrammeId = assetEntity.CountryProgramId, WareHouseId = (Guid)assetEntity.CurrentWareHouseId
                            };
                            context.Inventories.Add(newinvetoryEntity);
                        }

                        if (assetEntity.IsFleet)
                        {
                            SessionData.CurrentSession.FleetDetailsList = null;
                            context.FleetDetails.Add(new FleetDetail()
                            {
                                Id = Guid.NewGuid(), CountryProgrammeId = assetEntity.CountryProgramId, AssetId = assetEntity.Id, IssueDate = DateTime.Now
                            });
                        }

                        if (assetEntity.DepreciationType == "Zero Percentage")
                        {
                            if (!(context.SaveChanges() > 0))
                            {
                                scope.Dispose(); return(false);
                            }
                            else
                            {
                                scope.Complete(); return(true);
                            }
                        }
                        else
                        {
                            assetEntity.DepreciationPeriods = assetEntity.Lifespan * 12;
                        }
                        return(this.IsDepreciationComputed(context, scope, assetEntity));
                    }
                    catch (Exception ex) { scope.Dispose(); throw ex; }
                }
            }
        }
        //
        // GET: /ShippingTerm/Delete/5

        public ActionResult Delete(Guid id)
        {
            using (var db = new SCMSEntities())
            {
                db.ShippingTerms.Remove(db.ShippingTerms.SingleOrDefault(p => p.Id == id));
                db.SaveChanges();
            }
            return(ListView());
        }
Exemple #27
0
 public void DeleteGeneralLedgerById(Guid id)
 {
     using (var context = new SCMSEntities())
     {
         var gl = context.GeneralLedgers.FirstOrDefault(g => g.Id == id);
         context.GeneralLedgers.Remove(gl);
         context.SaveChanges();
     }
 }
Exemple #28
0
 public bool EditPackage(ItemPackage pack)
 {
     using (var context = new SCMSEntities())
     {
         context.ItemPackages.Attach(pack);
         ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(pack, System.Data.EntityState.Modified);
         return(context.SaveChanges() > 0 ? true : false);
     }
 }
Exemple #29
0
 public bool Delete <T>(T entity) where T : AttachedDocument
 {
     using (var context = new SCMSEntities())
     {
         ClearAttachedDocSession();
         ((IObjectContextAdapter)context).ObjectContext.CreateObjectSet <T>().DeleteObject(entity);
         return(context.SaveChanges() > 0 ? true : false);
     }
 }
Exemple #30
0
 public void InsertTenderingType(TenderingType entity)
 {
     using (var context = new SCMSEntities())
     {
         context.TenderingTypes.Add(entity);
         context.SaveChanges();
         ClearTTSessionData();
     }
 }