/// <summary>
        /// Set the values to be saved on entity CS_EquipmentCoverage on DB
        /// </summary>
        /// <returns></returns>
        private CS_EquipmentCoverage SetEquipmentCoverage()
        {
            CS_EquipmentCoverage equipmentCoverage = new CS_EquipmentCoverage();

            equipmentCoverage.Active = true;
            if (_view.CoverageStartDate.HasValue)
                equipmentCoverage.CoverageStartDate = _view.CoverageStartDate.Value;

            if (_view.EquipmentCoverageDuration.HasValue)
                equipmentCoverage.Duration = _view.EquipmentCoverageDuration.Value;

            equipmentCoverage.CreatedBy = _view.Username;
            equipmentCoverage.CreationDate = DateTime.Now;
            equipmentCoverage.DivisionID = _view.DivisionID;
            equipmentCoverage.EquipmentID = _view.EquipmentID;

            equipmentCoverage.ModificationDate = DateTime.Now;

            if (_view.CoverageEndDate.HasValue)
                equipmentCoverage.CoverageEndDate = _view.CoverageEndDate.Value;

            equipmentCoverage.ModifiedBy = _view.Username;
            //equipmentCoverage.CreationID;
            //equipmentCoverage.ModificationID;

            return equipmentCoverage;
        }
        /// <summary>
        /// Update the equipmentcoverage entity
        /// </summary>
        /// <param name="equipmentCoverage"></param>
        public void UpdateEquipmentCoverage(CS_EquipmentCoverage equipmentCoverage)
        {
            if (null == equipmentCoverage)
                throw new Exception("The EquipmentCoverage object is null.");

            try
            {
                _equipmentCoverageRepository.Update(equipmentCoverage);
            }
            catch (Exception ex)
            {
                throw new Exception("Error while trying to save the equipmentcoverage object.", ex);
            }
        }
 private void LoadEquipmentCoverageFields(CS_EquipmentCoverage equipmentCoverage)
 {
     if (null != equipmentCoverage && !equipmentCoverage.CoverageEndDate.HasValue)
     {
         _view.IsEquipmentCoverage = true;
         _view.EquipmentCoverageStartFields = true;
         _view.EquipmentCoverageEndFields = false;
         _view.CoverageEndDate = DateTime.Now;
     }
     else
     {
         _view.IsEquipmentCoverage = false;
         _view.EquipmentCoverageStartFields = false;
         _view.EquipmentCoverageEndFields = false;
         _view.CoverageEndDate = null;
         _view.DivisionName = string.Empty;
         _view.EquipmentCoverageDuration = null;
     }
 }
        public void SaveEquipment(CS_Equipment equipment, CS_EquipmentCoverage equipmentCoverage, CS_EquipmentWhiteLight equipmentWhiteLight, IList<CS_EquipmentWhiteLight> comboEquipmentsWhiteLight, CS_EquipmentDownHistory equipmentDownHistory, IList<CS_EquipmentDownHistory> equipmentComboDownHistory, bool isHeavyEquipment, bool isSeasonal, bool displayInResourceAllocation, bool replicateToCombo, bool IsEquipmentCoverage, bool IsEquipmentWhiteLight, string username)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                #region [ Equipment/EquipmentDown ]
                SaveEquipment(equipment, equipmentDownHistory, equipmentComboDownHistory, isHeavyEquipment, isSeasonal, displayInResourceAllocation, replicateToCombo);
                #endregion

                #region [ EquipmentCoverage ]

                CS_EquipmentCoverage eCoverage = GetEquipmentCoverage(equipment.ID);

                if (IsEquipmentCoverage)
                {
                    if (null != eCoverage)
                    {
                        eCoverage.CoverageStartDate = equipmentCoverage.CoverageStartDate;
                        eCoverage.DivisionID = equipmentCoverage.DivisionID;
                        eCoverage.Duration = equipmentCoverage.Duration;
                        eCoverage.ModifiedBy = equipmentCoverage.ModifiedBy;
                        eCoverage.ModificationDate = equipmentCoverage.ModificationDate;

                        //Update equipmentcoverage
                        UpdateEquipmentCoverage(eCoverage);
                    }
                    else
                    {
                        //Save equipmentcoverage
                        SaveEquipmentCoverage(equipmentCoverage);

                        using (_callLogModel = new CallLogModel())
                        {
                            _callLogModel.CreateCoverageCallLogs(equipment.ID, equipmentCoverage, username);
                        }
                    }
                }
                else
                {
                    if (null != eCoverage)
                    {
                        eCoverage.Active = false;
                        eCoverage.CoverageStartDate = equipmentCoverage.CoverageStartDate;
                        eCoverage.DivisionID = equipmentCoverage.DivisionID;
                        eCoverage.Duration = equipmentCoverage.Duration;
                        if (equipmentCoverage.CoverageEndDate.HasValue)
                        {
                            eCoverage.CoverageEndDate = equipmentCoverage.CoverageEndDate.Value;
                            eCoverage.ModificationDate = equipmentCoverage.CoverageEndDate.Value;
                        }
                        eCoverage.ModifiedBy = equipmentCoverage.ModifiedBy;

                        //Update equipmentcoverage when user uncheck the coverage checkbox
                        UpdateEquipmentCoverage(eCoverage);
                    }
                }

                #endregion

                #region [ WhiteLight ]

                CS_EquipmentWhiteLight eWhiteLight = GetEquipmentWhiteLight(equipment.ID);

                if (null != eWhiteLight)
                {
                    if (!IsEquipmentWhiteLight)
                    {
                        equipmentWhiteLight.ID = eWhiteLight.ID;
                        equipmentWhiteLight.WhiteLightEndDate = DateTime.Now;
                        equipmentWhiteLight.Active = false;
                        equipmentWhiteLight.ModificationDate = DateTime.Now;
                        equipmentWhiteLight.ModifiedBy = equipment.ModifiedBy;
                        if (!string.IsNullOrEmpty(equipmentWhiteLight.Notes))
                            equipmentWhiteLight.Notes = eWhiteLight.Notes + "\n" + equipmentWhiteLight.Notes;

                        UpdateEquipmentWhiteLight(equipmentWhiteLight);
                        if (replicateToCombo)
                        {
                            for (int i = 0; i < comboEquipmentsWhiteLight.Count; i++)
                            {
                                CS_EquipmentWhiteLight eWhiteLightCombo = GetEquipmentWhiteLight(comboEquipmentsWhiteLight[i].EquipmentID);
                                comboEquipmentsWhiteLight[i].ID = eWhiteLightCombo.ID;
                                comboEquipmentsWhiteLight[i].WhiteLightEndDate = DateTime.Now;
                                comboEquipmentsWhiteLight[i].Active = false;
                                comboEquipmentsWhiteLight[i].ModificationDate = DateTime.Now;
                                comboEquipmentsWhiteLight[i].ModifiedBy = equipment.ModifiedBy;
                                if (!string.IsNullOrEmpty(comboEquipmentsWhiteLight[i].Notes))
                                    comboEquipmentsWhiteLight[i].Notes = eWhiteLight.Notes + "\r\n" + comboEquipmentsWhiteLight[i].Notes;
                                UpdateEquipmentWhiteLight(comboEquipmentsWhiteLight[i]);
                            }
                        }
                    }
                }
                else
                {
                    if (IsEquipmentWhiteLight)
                    {
                        SaveEquipmentWhiteLight(equipmentWhiteLight);
                        if (replicateToCombo)
                        {
                            for (int i = 0; i < comboEquipmentsWhiteLight.Count; i++)
                            {
                                SaveEquipmentWhiteLight(comboEquipmentsWhiteLight[i]);
                            }
                        }
                    }
                }
                #endregion

                scope.Complete();
            }
        }