public void TestIfEmployeeIsBeingUpdated()
        {
            // Arrange
            FakeObjectSet<CS_Employee> fakeEmployeeList = new FakeObjectSet<CS_Employee>();
            FakeObjectSet<CS_CallCriteria> fakeCallCriteriaList = new FakeObjectSet<CS_CallCriteria>();
            FakeObjectSet<CS_CallCriteriaValue> fakeCallCriteriaValueList = new FakeObjectSet<CS_CallCriteriaValue>();
            FakeObjectSet<CS_EmployeeCoverage> fakeEmployeeCoverageList = new FakeObjectSet<CS_EmployeeCoverage>();
            FakeObjectSet<CS_EmployeeOffCallHistory> fakeEmployeeOffCallList = new FakeObjectSet<CS_EmployeeOffCallHistory>();
            FakeObjectSet<CS_Settings> fakeSettingsList = new FakeObjectSet<CS_Settings>();
            FakeObjectSet<CS_CallLog> fakeCallLogList = new FakeObjectSet<CS_CallLog>();
            FakeObjectSet<CS_CallLogResource> fakeCallLogResourceList = new FakeObjectSet<CS_CallLogResource>();
            FakeObjectSet<CS_Resource> fakeResourceList = new FakeObjectSet<CS_Resource>();
            FakeObjectSet<CS_PhoneNumber> fakePhoneList = new FakeObjectSet<CS_PhoneNumber>();

            fakeEmployeeList.AddObject(
                new CS_Employee()
                {
                    ID = 1,
                    Active = true,
                    HasAddressChanges = false,
                    HasPhoneChanges = false,
                }
            );
            fakeEmployeeList.AddObject(
                new CS_Employee()
                {
                    ID = 2,
                    Active = true,
                    HasAddressChanges = false,
                    HasPhoneChanges = false,
                }
            );
            fakeSettingsList.AddObject(
                new CS_Settings()
                {
                    ID = (int)Globals.Configuration.Settings.AddressChangeNotification,
                    Description = "*****@*****.**"
                }
            );

            Mock<IUnitOfWork> mockUnitOfWork = new Mock<IUnitOfWork>();
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_Employee>()).Returns(fakeEmployeeList);
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_CallCriteria>()).Returns(fakeCallCriteriaList);
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_CallCriteriaValue>()).Returns(fakeCallCriteriaValueList);
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_EmployeeCoverage>()).Returns(fakeEmployeeCoverageList);
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_EmployeeOffCallHistory>()).Returns(fakeEmployeeOffCallList);
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_Settings>()).Returns(fakeSettingsList);
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_CallLog>()).Returns(fakeCallLogList);
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_CallLogResource>()).Returns(fakeCallLogResourceList);
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_Resource>()).Returns(fakeResourceList);
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_PhoneNumber>()).Returns(fakePhoneList);

            CS_Employee updateEmployee = new CS_Employee()
            {
                ID = 1,
                Address = "Testing Address"
            };

            CS_CallCriteria callCriteria = new CS_CallCriteria()
            {
                EmployeeID = 1,
                Active = true
            };

            IList<CS_CallCriteriaValue> callCriteriaValueList = new List<CS_CallCriteriaValue>();
            callCriteriaValueList.Add(new CS_CallCriteriaValue()
            {
                CallCriteriaTypeID = 1,
                Value = "testing",
                Active = true

            });

            CS_EmployeeCoverage coverage = new CS_EmployeeCoverage()
            {
                EmployeeID = 1,
                Active = true,
                CoverageStartDate = new DateTime(2011, 8, 29),
                Duration = 10,
                DivisionID = 1,
                CS_Employee = new CS_Employee() { ID = 1, Active = true, FullName = "Santos, Kleiton" },
                CS_Division = new CS_Division() { ID = 1, Active = true, Name = "001" }
            };

            CS_EmployeeOffCallHistory offCall = new CS_EmployeeOffCallHistory()
            {
                EmployeeID = 1,
                ProxyEmployeeID = 2,
                Active = true,
                OffCallStartDate = new DateTime(2011, 8, 29),
                OffCallEndDate = new DateTime(2011, 8, 31),
                OffCallReturnTime = new TimeSpan(10, 0, 0),
                CS_Employee = new CS_Employee() { ID = 1, Active = true, FullName = "Santos, Kleiton" },
                CS_Employee_Proxy = new CS_Employee() { ID = 2, Active = true, FullName = "Burton, Cynthia" }
            };

            // Act
            EmployeeModel model = new EmployeeModel(mockUnitOfWork.Object);
            model.SaveEmployee(updateEmployee, offCall, coverage, "system", true, true, new List<DataContext.VO.PhoneNumberVO>());

            // Assert
            Assert.AreEqual(1, fakeCallCriteriaList.Count());
            Assert.AreEqual(1, fakeCallCriteriaValueList.Count());
            Assert.AreEqual(1, fakeEmployeeOffCallList.Count());
            Assert.AreEqual(1, fakeEmployeeCoverageList.Count());
        }
 /// <summary>
 /// Create a new CS_CallCriteria object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="modifiedBy">Initial value of the ModifiedBy property.</param>
 /// <param name="createdBy">Initial value of the CreatedBy property.</param>
 /// <param name="creationDate">Initial value of the CreationDate property.</param>
 /// <param name="modificationDate">Initial value of the ModificationDate property.</param>
 /// <param name="active">Initial value of the Active property.</param>
 public static CS_CallCriteria CreateCS_CallCriteria(global::System.Int32 id, global::System.String modifiedBy, global::System.String createdBy, global::System.DateTime creationDate, global::System.DateTime modificationDate, global::System.Boolean active)
 {
     CS_CallCriteria cS_CallCriteria = new CS_CallCriteria();
     cS_CallCriteria.ID = id;
     cS_CallCriteria.ModifiedBy = modifiedBy;
     cS_CallCriteria.CreatedBy = createdBy;
     cS_CallCriteria.CreationDate = creationDate;
     cS_CallCriteria.ModificationDate = modificationDate;
     cS_CallCriteria.Active = active;
     return cS_CallCriteria;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the CS_CallCriteria EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCS_CallCriteria(CS_CallCriteria cS_CallCriteria)
 {
     base.AddObject("CS_CallCriteria", cS_CallCriteria);
 }
 /// <summary>
 /// Updates an Employee Criteria and Values on the DB
 /// </summary>
 /// <param name="criteria">Criteria Entity</param>
 /// <param name="criteriaValuesList">Criteria Values Entity List</param>
 /// <param name="username">Current app Username</param>
 public void UpdateEmployeeCriteria(CS_CallCriteria criteria, IList<CS_CallCriteriaValue> addedList, IList<CS_CallCriteriaValue> removedList, IList<CS_CallCriteriaValue> updatedList, string username)
 {
     using (TransactionScope scope = new TransactionScope())
     {
         UpdateCriteria(criteria, addedList, removedList, updatedList, username);
         scope.Complete();
     }
 }
        public void TestSaveEmployeeCriteria()
        {
            CallCriteriaModel model = new CallCriteriaModel(new FakeUnitOfWork());

            CS_CallCriteria newCriteria = new CS_CallCriteria()
            {
                EmployeeID = 1
            };

            FakeObjectSet<CS_CallCriteriaValue> newCriteriaValueList = new FakeObjectSet<CS_CallCriteriaValue>();
            newCriteriaValueList.AddObject(new CS_CallCriteriaValue()
            {
                CallCriteriaTypeID = 1,
                Value = "Test"
            });

            newCriteriaValueList.AddObject(new CS_CallCriteriaValue()
            {
                CallCriteriaTypeID = 2,
                Value = "Test2"
            });

            Assert.IsTrue(model.SaveCriteria(newCriteria, newCriteriaValueList.ToList(), "Testing"), "Test finalized with no Exceptions but, there may be errors in the Data inside");
        }
        /// <summary>
        /// Updates a Criteria and Values on the DB
        /// </summary>
        /// <param name="criteria">Criteria Entity</param>
        /// <param name="criteriaValuesList">Criteria Values Entity List</param>
        /// <param name="username">Current app Username</param>
        public void UpdateCriteria(CS_CallCriteria criteria, IList<CS_CallCriteriaValue> addedList, IList<CS_CallCriteriaValue> removedList, IList<CS_CallCriteriaValue> updatedList, string username)
        {
            if (null == criteria)
            {
                Exception ex = new Exception("The Call Criteria object is null!");
                Logger.Write(string.Format("The Call Criteria object is null.\n{0}\n{1}", ex, ex.InnerException));
                throw ex;
            }

            if (null == addedList || null == removedList)
            {
                Exception ex = new Exception("The Call Criteria Value List object is null!");
                Logger.Write(string.Format("The Call Criteria Value List object is null.\n{0}\n{1}", ex, ex.InnerException));
                throw ex;
            }

            try
            {
                criteria.ModifiedBy = username;
                criteria.ModificationDate = DateTime.Now;

                criteria = _callCriteriaRepository.Update(criteria);
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An error while trying to save Call Criteria information.\n{0}\n{1}", ex, ex.InnerException));
                throw new Exception("Error while trying to save Call Criteria information!", ex);
            }

            try
            {
                for (int i = 0; i < addedList.Count; i++)
                {
                    addedList[i].CallCriteriaID = criteria.ID;
                    addedList[i].CreatedBy = username;
                    addedList[i].CreationDate = DateTime.Now;
                    addedList[i].ModifiedBy = username;
                    addedList[i].ModificationDate = DateTime.Now;
                    addedList[i].Active = true;
                }

                _callCriteriaValueRepository.AddList(addedList);

                for (int i = 0; i < removedList.Count; i++)
                {
                    removedList[i].ModifiedBy = username;
                    removedList[i].ModificationDate = DateTime.Now;
                    removedList[i].Active = false;
                }

                _callCriteriaValueRepository.UpdateList(removedList);

                for (int i = 0; i < updatedList.Count; i++)
                {
                    updatedList[i].ModifiedBy = username;
                    updatedList[i].ModificationDate = DateTime.Now;
                    updatedList[i].Active = true;
                }

               // removedList.AddRange(updatedList);
                _callCriteriaValueRepository.UpdateList(updatedList);
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An error while trying to save Call Criteria Values information.\n{0}\n{1}", ex, ex.InnerException));
                throw new Exception("Error while trying to save Call Criteria Values information!", ex);
            }
        }
 /// <summary>
 /// Inserts a new Employee Criteria and Values into the DB
 /// </summary>
 /// <param name="criteria">Criteria Entity</param>
 /// <param name="criteriaValuesList">Criteria Values Entity List</param>
 /// <param name="username">Current app Username</param>
 public bool SaveEmployeeCriteria(CS_CallCriteria criteria, IList<CS_CallCriteriaValue> criteriaValuesList, string username)
 {
     return SaveCriteria(criteria, criteriaValuesList, username);
 }
        /// <summary>
        /// Inserts a new Criteria and Values into the DB
        /// </summary>
        /// <param name="criteria">Criteria Entity</param>
        /// <param name="criteriaValuesList">Criteria Values Entity List</param>
        /// <param name="username">Current app Username</param>
        public bool SaveCriteria(CS_CallCriteria criteria, IList<CS_CallCriteriaValue> criteriaValuesList, string username)
        {
            if (null == criteria)
            {
                Exception ex = new Exception("The Call Criteria object is null!");
                Logger.Write(string.Format("The Call Criteria object is null.\n{0}\n{1}", ex, ex.InnerException));
                throw ex;
            }

            if (null == criteriaValuesList)
            {
                Exception ex = new Exception("The Call Criteria Value Value object is null!");
                Logger.Write(string.Format("The Call Criteria Value object is null.\n{0}\n{1}", ex, ex.InnerException));
                throw ex;
            }

            try
            {
                criteria.CreatedBy = username;
                criteria.CreationDate = DateTime.Now;
                criteria.ModifiedBy = username;
                criteria.ModificationDate = DateTime.Now;
                criteria.Active = true;

                criteria = _callCriteriaRepository.Add(criteria);
            }

            catch (Exception ex)
            {
                Logger.Write(string.Format("An error while trying to save Criteria information.\n{0}\n{1}", ex, ex.InnerException));
                throw new Exception("Error while trying to save Criteria information!", ex);
            }

            try
            {
                if (null != criteriaValuesList)
                {
                    for (int i = 0; i < criteriaValuesList.Count; i++)
                    {
                        criteriaValuesList[i].CallCriteriaID = criteria.ID;
                        criteriaValuesList[i].CreatedBy = username;
                        criteriaValuesList[i].CreationDate = DateTime.Now;
                        criteriaValuesList[i].ModifiedBy = username;
                        criteriaValuesList[i].ModificationDate = DateTime.Now;
                        criteriaValuesList[i].Active = true;
                    }

                    _callCriteriaValueRepository.AddList(criteriaValuesList);
                }
            }

            catch (Exception ex)
            {
                Logger.Write(string.Format("An error while trying to save Criteria Values information.\n{0}\n{1}", ex, ex.InnerException));
                throw new Exception("Error while trying to save Criteria Values information!", ex);
            }

            return true;
        }
        /// <summary>
        /// Inserts a new Customer Criteria and Values into the DB
        /// </summary>
        /// <param name="criteria">Criteria Entity</param>
        /// <param name="criteriaValuesList">Criteria Values Entity List</param>
        /// <param name="username">Current app Username</param>
        public bool SaveContactCriteria(CS_CallCriteria criteria, IList<CS_CallCriteriaValue> criteriaValuesList, string username)
        {
            bool returnValue = false;
            using (TransactionScope scope = new TransactionScope())
            {
                returnValue = SaveCriteria(criteria, criteriaValuesList, username);

                scope.Complete();
            }
            return returnValue;
        }
        public void SaveCallCriteria(CS_CallCriteria saveCriteria, IList<CS_CallCriteriaValue> saveCriteriaValueList, string username)
        {
            try
            {
                if (0 == saveCriteria.ID)
                    SaveEmployeeCriteria(saveCriteria, saveCriteriaValueList, username);
                else
                {
                    // Update Call Criteria
                    List<CS_CallCriteriaValue> removedList = null;
                    List<CS_CallCriteriaValue> addedList = null;
                    List<CS_CallCriteriaValue> updatedList = null;

                    IList<CS_CallCriteriaValue> oldList = ListAllCallCriteriaValuesListById(saveCriteria.ID);
                    removedList = oldList.Where(e => !saveCriteriaValueList.Any(f => f.CallCriteriaTypeID == e.CallCriteriaTypeID && f.Value == e.Value)).ToList();
                    addedList = saveCriteriaValueList.Where(e => !oldList.Any(f => f.CallCriteriaTypeID == e.CallCriteriaTypeID && f.Value == e.Value)).ToList();
                    updatedList = saveCriteriaValueList.Where(e => oldList.Any(f => f.CallCriteriaTypeID == e.CallCriteriaTypeID && f.Value == e.Value)).ToList();

                    for (int i = 0; i < updatedList.Count; i++)
                    {
                        CS_CallCriteriaValue ccValue = oldList.FirstOrDefault(f => f.CallCriteriaTypeID == updatedList[i].CallCriteriaTypeID && f.Value == updatedList[i].Value);

                        updatedList[i].CallCriteriaID = ccValue.CallCriteriaID;
                        updatedList[i].ID = ccValue.ID;
                        updatedList[i].CreatedBy = ccValue.CreatedBy;
                        updatedList[i].CreationDate = ccValue.CreationDate;
                        updatedList[i].CreationID = ccValue.CreationID;
                    }

                    UpdateEmployeeCriteria(saveCriteria, addedList, removedList, updatedList, username);
                }
            }
            catch (Exception ex)
            {
                Logger.Write(string.Format("An error occured while trying to Update Call Criteria Information.\n{0}\n{1}", ex, ex.InnerException));
                throw new Exception("Error while updating Call Criteria information", ex);
            }
        }