/// <summary>
        /// Updates DPI and its resources (only for screen, not for processing)
        /// </summary>
        /// <param name="currentDPI">Current DPI</param>
        /// <param name="dpiResources">Resources of the DPI</param>
        /// <param name="specialPricing">Special Pricing Information</param>
        /// <param name="manualSpecialPricingList">Manual Special Pricing Table</param>
        public void UpdateDPI(CS_DPI currentDPI, IList<CS_DPIResource> dpiResources, CS_DPISpecialPricing specialPricing, IList<CS_DPIManualSpecialPricing> manualSpecialPricingList)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                decimal total = UpdateDPI(currentDPI, dpiResources, DateTime.Now);

                if (null != specialPricing)
                {
                    CS_DPISpecialPricing oldSpecialPricing = _dpiSpecialPricingRepository.Get(e => e.DPIID == currentDPI.ID && e.Active);
                    if (null == oldSpecialPricing)
                        _dpiSpecialPricingRepository.Add(specialPricing);
                    else
                        _dpiSpecialPricingRepository.Update(specialPricing);
                }

                if (manualSpecialPricingList.Count > 0)
                {
                    IList<CS_DPIManualSpecialPricing> oldManualList = _dpiManualSpecialPricingRepository.ListAll(e => e.Active && e.DPIId == currentDPI.ID);
                    List<int> currentManualIDs = manualSpecialPricingList.Select(e => e.ID).ToList();

                    List<CS_DPIManualSpecialPricing> addList = manualSpecialPricingList.Where(e => e.ID == 0).ToList();
                    List<CS_DPIManualSpecialPricing> updateList = manualSpecialPricingList.Where(e => e.ID != 0).ToList();
                    List<CS_DPIManualSpecialPricing> removeList = oldManualList.Where(e => !currentManualIDs.Contains(e.ID)).ToList();

                    for (int i = 0; i < removeList.Count; i++)
                    {
                        removeList[i].ModificationDate = currentDPI.ModificationDate;
                        removeList[i].ModifiedBy = currentDPI.ModifiedBy;
                        //removeList[i].ModificationID = currentDPI.ModificationID;
                        removeList[i].Active = false;
                    }

                    _dpiManualSpecialPricingRepository.AddList(addList);
                    _dpiManualSpecialPricingRepository.UpdateList(updateList);
                    _dpiManualSpecialPricingRepository.UpdateList(removeList);
                }

                if (currentDPI.ProcessStatus == (short)Globals.DPI.DpiStatus.Approved)
                {
                    currentDPI.Total = total;
                    _callLogRepository.Add(SetCallLogDPIProcess(currentDPI));
                }

                scope.Complete();
            }
        }
        /// <summary>
        /// Saves the DPI
        /// </summary>
        public void SaveDPI()
        {
            CS_DPI dpi = _dpiModel.GetDPI(_view.DPIId);
            if (null != dpi)
            {
                DateTime modificationDate = DateTime.Now;

                dpi.ProcessStatus = (short)_view.DPIStatus;
                dpi.ProcessStatusDate = modificationDate;

                if (dpi.ProcessStatus == (short)Globals.DPI.DpiStatus.Approved)
                    dpi.ApprovedBy = _view.LoggedEmployee;

                dpi.ModifiedBy = _view.Username;
                dpi.ModificationDate = modificationDate;
                dpi.Total = _view.DPIResources.Where(e => e.Active).Sum(e => e.Total);

                IList<CS_DPIResource> oldResourceList = _dpiModel.ListDPIResources(_view.DPIId);
                IList<CS_DPIResource> newResourceList = _view.DPIResources;

                foreach (CS_DPIResource newResource in newResourceList)
                {
                    CS_DPIResource oldResource = oldResourceList.FirstOrDefault(e => e.ID == newResource.ID);
                    if (null != oldResource)
                    {
                        newResource.DPIID = oldResource.DPIID;
                        newResource.EquipmentID = oldResource.EquipmentID;
                        newResource.EmployeeID = oldResource.EmployeeID;
                        newResource.CalculationStatus = oldResource.CalculationStatus;
                        newResource.Hours = oldResource.Hours;
                        newResource.Rate = oldResource.Rate;

                        newResource.CreatedBy = oldResource.CreatedBy;
                        //newResource.CreationID = oldResource.CreationID;
                        newResource.CreationDate = oldResource.CreationDate;

                        newResource.ModifiedBy = _view.Username;
                        //newResource.ModificationID = null;
                        newResource.ModificationDate = modificationDate;

                        newResource.Active = oldResource.Active;
                    }
                }

                CS_DPISpecialPricing newSpecialPricing = null;
                IList<CS_DPIManualSpecialPricing> newManualSpecialPricingList = new List<CS_DPIManualSpecialPricing>();

                if (_view.ViewSpecialPricing)
                {
                    newSpecialPricing = new CS_DPISpecialPricing();
                    newSpecialPricing.DPIID = _view.DPIId;
                    newSpecialPricing.Type = (int)_view.SpecialPriceType;
                    newSpecialPricing.OverallJobDiscount = _view.OverallJobDiscount;
                    newSpecialPricing.LumpSumValue = _view.LumpSumValue;
                    newSpecialPricing.LumpSumDuration = _view.LumpSumDuration;
                    newSpecialPricing.LumpSumValuePerDay = _view.LumpSumValuePerDay;
                    newSpecialPricing.Notes = _view.SpecialPricingNotes;

                    if (null != dpi.CS_DPISpecialPricing)
                    {
                        newSpecialPricing.CreationDate = dpi.CS_DPISpecialPricing.CreationDate;
                        newSpecialPricing.CreatedBy = dpi.CS_DPISpecialPricing.CreatedBy;
                        newSpecialPricing.CreationID = dpi.CS_DPISpecialPricing.CreationID;
                    }
                    else
                    {
                        newSpecialPricing.CreationDate = modificationDate;
                        newSpecialPricing.CreatedBy = _view.Username;
                        //newSpecialPricing.CreationID = null;
                    }

                    newSpecialPricing.ModificationDate = modificationDate;
                    newSpecialPricing.ModifiedBy = _view.Username;
                    //newSpecialPricing.ModificationID = null;

                    newSpecialPricing.Active = true;

                    if (null != _view.ManualSpecialPricingTable)
                    {
                        for (int i = 0; i < _view.ManualSpecialPricingTable.Count; i++)
                        {
                            CS_DPIManualSpecialPricing oldItem = _view.ManualSpecialPricingTable[i];
                            CS_DPIManualSpecialPricing newItem = new CS_DPIManualSpecialPricing();

                            newItem.ID = oldItem.ID;
                            newItem.DPIId = _view.DPIId;
                            newItem.Description = oldItem.Description;
                            newItem.QtdHrs = oldItem.QtdHrs;
                            newItem.Rate = oldItem.Rate;

                            if (oldItem.ID.Equals(0))
                            {
                                newItem.CreationDate = modificationDate;
                                newItem.CreatedBy = _view.Username;
                                //newItem.CreationID = null;
                            }
                            else
                            {
                                newItem.CreationDate = oldItem.CreationDate;
                                newItem.CreatedBy = oldItem.CreatedBy;
                            }
                            newItem.ModificationDate = modificationDate;
                            newItem.ModifiedBy = _view.Username;
                            //newItem.ModificationID = null;
                            newItem.Active = true;

                            newManualSpecialPricingList.Add(newItem);
                        }
                    }
                }

                _dpiModel.UpdateDPI(dpi, newResourceList, newSpecialPricing, newManualSpecialPricingList);
            }
        }