Beispiel #1
0
 public DepartmentWithOfficesModel(IDepartmentModel department, IEnumerable <IOfficeModel> offices)
     : base(department.ApplicationId, department.DepartmentId, department.ParentDepartmentId, department.Name, department.OfficeId)
 {
     this.Office           = department.Office;
     this.ParentDepartment = department.ParentDepartment;
     this.Offices          = new List <IOfficeModel>(offices);
 }
Beispiel #2
0
        public BusinessObjectActionReport <DataRepositoryActionStatus> Update(IDepartmentModel department)
        {
            BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success);

            businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(department);
            if (businessObjectActionReport.ValidationResult.IsValid)
            {
                int num;
                try
                {
                    using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext())
                        num = dataStoreContext.wm_Departments_Update(department.DepartmentId, department.ParentDepartmentId, department.Name, department.OfficeId);
                }
                catch (Exception ex)
                {
                    _Log.Error("Error at wm_Departments_Update", ex);
                    throw new DataStoreException(ex, true);
                }
                if (num == 0)
                {
                    businessObjectActionReport.Status = DataRepositoryActionStatus.NoRecordRowAffected;
                    _Log.ErrorFormat("Department {0} was not updated at the database, NoRecordRowAffected"
                                     , DebugUtility.GetObjectString(department));
                }
            }
            else
            {
                businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed;
                _Log.WarnFormat("Department {0} was not updated at the database because the validation failed.\nReport: {1}"
                                , DebugUtility.GetObjectString(department)
                                , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII));
            }
            return(businessObjectActionReport);
        }
        public void ValidateDepartmentUrl(IDepartmentModel departmentModel)
        {
            Uri uriAddress = new Uri(departmentModel.Url);

            string domainExtension = Path.GetExtension(uriAddress.Host).Trim().ToLower();

            if (!".com .net".Contains(domainExtension))
            {
                _experimentalBuilder.Add("Department Url has to contain .com or .net extensions.");
            }

            if (departmentModel.Url.Length < 7 || departmentModel.Url.Length > 30)
            {
                _experimentalBuilder.Add("Department Url has to be between 7 and 30 characters.");
            }

            if (uriAddress.GetLeftPart(UriPartial.Scheme) != "http://")
            {
                _experimentalBuilder.Add("Department Url must only have http:// protocol.");
            }

            //if(!"http:// ftp://".Contains(uriAddress.GetLeftPart(UriPartial.Scheme)))
            //{
            //    //***
            //}
        }
Beispiel #4
0
        internal static void Delete(IDataStore dataStore, IDepartmentModel department)
        {
            DepartmentManager manager = new DepartmentManager(dataStore);

            int num = manager.Delete(department.ApplicationId, department.DepartmentId);

            Assert.GreaterOrEqual(num, 1);
            Assert.IsNull(manager.GetDepartment(department.ApplicationId, department.DepartmentId));

            Trace.WriteLine("Successfully deleted department " + department.Name);
        }
        public void ValidateModel(IDepartmentModel departmentModel)
        {
            this.ValidateModelFluentBuilder(departmentModel);
            if (CheckIfValidationIsTrueFluentBuilder(_modelValidationCheck.IsValidationFalse))
            {
                ErrorCodes    = _modelValidationCheck.Errors["ErrorCode"];
                ErrorMessages = _modelValidationCheck.Errors["ErrorMessage"];

                this.ResetModelValidationChecksErrors();
            }
        }
        public void ValidateDepartmentCityLocation(IDepartmentModel departmentModel)
        {
            var checks = new AdditionalValidChecks(new AdditionalValidForInt(), new AdditionalValidForString());

            string cityLocation = departmentModel.CityLocation;

            if (!checks.ForString.BeAValidCityLocation(cityLocation))
            {
                _experimentalBuilder.Add("Department city location is in wrong format.");
            }
        }
        public void ValidateDepartmentID(IDepartmentModel departmentModel)
        {
            var checks = new AdditionalValidChecks(new AdditionalValidForInt(), new AdditionalValidForString());

            int iD = departmentModel.ID;

            if (!checks.ForInt.BeAValidID(iD))
            {
                _experimentalBuilder.Add("Department iD is in wrong format.");
            }
        }
        public void ValidateDepartmentName(IDepartmentModel departmentModel)
        {
            var checks = new AdditionalValidChecks(new AdditionalValidForInt(), new AdditionalValidForString());

            string name = departmentModel.Name;

            if (!checks.ForString.BeAValidName(name))
            {
                _experimentalBuilder.Add("Department name is in wrong format.");
            }
        }
Beispiel #9
0
        public void Test_Gets()
        {
            DepartmentManager manager = new DepartmentManager(this.DataStore);

            IOfficeModel office_A = Test_Offices.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application
                                                        , this.DummyDataManager, this.Random);
            IOfficeModel office_B_And_C = Test_Offices.Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application
                                                              , this.DummyDataManager, this.Random);

            IDepartmentModel record_C = Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application
                                               , this.DummyDataManager, this.Random);
            IDepartmentModel record_B = Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application
                                               , this.DummyDataManager, this.Random);
            IDepartmentModel record_A = Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application
                                               , this.DummyDataManager, this.Random);

            record_C.OfficeId           = office_B_And_C.OfficeId;
            record_C.ParentDepartmentId = record_B.DepartmentId;
            manager.Update(record_C);

            record_B.OfficeId           = office_B_And_C.OfficeId;
            record_B.ParentDepartmentId = record_A.DepartmentId;
            manager.Update(record_B);

            record_A.OfficeId = office_A.OfficeId;
            manager.Update(record_A);

            IDepartmentWithOfficesModel record = manager.GetDepartment(this.Application.ApplicationId, record_C.DepartmentId);

            Assert.IsNotNull(record);
            Assert.IsNotNull(record.Office);
            Assert.IsNotNull(record.ParentDepartment);
            Assert.IsNotNull(record.ParentDepartment.Office);
            Assert.IsNotNull(record.ParentDepartment.ParentDepartment);
            Assert.IsNotNull(record.ParentDepartment.ParentDepartment.Office);

            Assert.IsNull(record.ParentDepartment.ParentDepartment.ParentDepartment);

            Assert.AreEqual(record.Office.OfficeId, office_B_And_C.OfficeId);
            Assert.AreEqual(record_B.DepartmentId, record.ParentDepartment.DepartmentId);
            Assert.AreEqual(record_B.OfficeId, record.ParentDepartment.Office.OfficeId);

            Assert.AreEqual(record_A.DepartmentId, record.ParentDepartment.ParentDepartment.DepartmentId);
            Assert.AreEqual(record_A.OfficeId, record.ParentDepartment.ParentDepartment.Office.OfficeId);

            Assert.IsNotNull(record.Offices);
            Assert.GreaterOrEqual(record.Offices.Count, 2);
            Assert.IsNotNull(record.Offices.Find(c => c.OfficeId == office_A.OfficeId));
            Assert.IsNotNull(record.Offices.Find(c => c.OfficeId == office_B_And_C.OfficeId));

            Test_Offices.Delete(this.DataStore, office_A);
            Delete(this.DataStore, record_A);
            Test_Offices.Delete(this.DataStore, office_B_And_C);
        }
        private void ValidateDepartmentUrl(IDepartmentModel departmentModel)
        {
            StringBuilder errorsStringBuilder = new StringBuilder();

            if (string.IsNullOrEmpty(departmentModel.DepartmentUrl))
            {
                errorsStringBuilder.Append("DepartmentUrl can't empyt");
            }
            if (departmentModel.DepartmentUrl.Length < 5)
            {
                errorsStringBuilder.Append("DepartmentUrl minimus lenght 5");
            }
        }
        private bool RecordExistsCheck(SqlCommand cmd, IDepartmentModel departmentModel, TypeOfExistenceCheck typeOfExistenceCheck,
                                       RequestType requestType)
        {
            Int32 count0fRecordsFound     = 0;
            bool  recordExistsCheckPassed = true;

            DataAccessStatus dataAccessStatus = new DataAccessStatus();
            SqlCommand       cmdCheck         = new SqlCommand(null, cmd.Connection);

            cmdCheck.Prepare();


            if ((requestType == RequestType.Add) || (requestType == RequestType.ConfirmAdd))
            {
                cmdCheck.CommandText = "SELECT count(*) FROM [Departments] where [Name] = @DepName";
                cmdCheck.Parameters.Add(new SqlParameter("@DepName", System.Data.SqlDbType.NVarChar, 40)).Value = departmentModel.DepartmentName;
            }
            else if ((requestType == RequestType.Update) || (requestType == RequestType.Delete) || (requestType == RequestType.ConfirmDelete))
            {
                cmdCheck.CommandText = "SELECT count(*) FROM [Departments] WHERE [ID] = @DepartId";
                cmdCheck.Parameters.Add(new SqlParameter("@DepartId", departmentModel.DepartmentId));
            }

            try
            {
                count0fRecordsFound = Convert.ToInt32(cmdCheck.ExecuteScalar());
            }
            catch (SqlException e)
            {
                string msg = e.Message;
                throw e;
            }

            if ((typeOfExistenceCheck == TypeOfExistenceCheck.DoesNotExistInDB) && (count0fRecordsFound > 0))
            {
                dataAccessStatus.Status = "Error";
                recordExistsCheckPassed = false;

                throw new DataAccessException(dataAccessStatus);
            }
            else if ((typeOfExistenceCheck == TypeOfExistenceCheck.DoesExistInDB) && (count0fRecordsFound == 0))
            {
                dataAccessStatus.Status = "Error";
                recordExistsCheckPassed = false;

                throw new DataAccessException(dataAccessStatus);
            }

            return(recordExistsCheckPassed);
        }
Beispiel #12
0
        internal IDepartmentModel Create(IDataStore dataStore, IApplicationSettings applicationSettings, IApplication application
                                         , DummyDataManager dtm, Random random)
        {
            DepartmentManager manager = new DepartmentManager(dataStore);

            IDepartmentModel department = new DepartmentModel(
                application.ApplicationId
                , "DepartmentName" + random.Next(1000000, 10000000));

            PopulateWithRandomValues(department, dtm, random);

            BusinessObjectActionReport <DataRepositoryActionStatus> report = manager.Create(application.ApplicationId, department);

            Assert.AreEqual(DataRepositoryActionStatus.Success, report.Status);

            IDepartmentModel dsDepartmentModel = manager.GetDepartment(department.ApplicationId, department.DepartmentId);

            Assert.IsNotNull(dsDepartmentModel);

            return(dsDepartmentModel);
        }
Beispiel #13
0
        public void Test_CreateUpdateDeleteDepartment()
        {
            DepartmentManager manager = new DepartmentManager(this.DataStore);
            IDepartmentModel  record  = Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application
                                               , this.DummyDataManager, this.Random);

            IDepartmentModel recordToCompare;

            for (int i = 0; i < this.DefaultUpdateTestIterations; i++)
            {
                PopulateWithRandomValues(record, this.DummyDataManager, this.Random);
                recordToCompare = record;

                manager.Update(record);
                record = manager.GetDepartment(record.ApplicationId, record.DepartmentId);

                string errors = string.Empty;

                Assert.IsTrue(DebugUtility.ArePropertyValuesEqual(record, recordToCompare, out errors), errors);
                Trace.WriteLine("Update test successfull.");
            }

            Delete(this.DataStore, record);
        }
 public void Update(IDepartmentModel departmentModel)
 {
     _departmentRepository.Update(departmentModel);
 }
 public void Delete(IDepartmentModel departmentModel)
 {
     _departmentRepository.Delete(departmentModel);
 }
 public void Add(IDepartmentModel departmentModel)
 {
     _departmentRepository.Add(departmentModel);
 }
 public void Update(IDepartmentModel departmentModel)
 {
     throw new NotImplementedException();
 }
        public void Remove(IDepartmentModel departmentModel)
        {
            DataAccessStatus dataAccessStatus = new DataAccessStatus();

            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                try
                {
                    sqlConnection.Open();
                }
                catch (SqlException e)
                {
                    dataAccessStatus.setValues(status: "Error", operationSucceeded: false, exceptionMessage: e.Message,
                                               customMessage: "Unable to Delete Department Model. Could not open database connection.",
                                               helpLink: e.HelpLink, errorCode: e.ErrorCode, stackTrace: e.StackTrace);

                    throw new DataAccessException(e.Message, e.InnerException, dataAccessStatus);
                }

                string deleteQuery = "DELETE FROM [Departments] WHERE [ID] = @DepartmentId";

                using (SqlCommand cmd = new SqlCommand(deleteQuery, sqlConnection))
                {
                    try
                    {
                        RecordExistsCheck(cmd, departmentModel, TypeOfExistenceCheck.DoesExistInDB, RequestType.Delete);
                    }
                    catch (DataAccessException e)
                    {
                        e.DataAccessStatusInfo.CustomMessage    = "Department model could not be deleted because it could not be found in the database";
                        e.DataAccessStatusInfo.ExceptionMessage = string.Copy(e.Message);
                        e.DataAccessStatusInfo.StackTrace       = string.Copy(e.StackTrace);

                        throw e;
                    }

                    cmd.CommandText = deleteQuery;

                    cmd.Prepare();
                    cmd.Parameters.AddWithValue("@DepartmentId", departmentModel.DepartmentId);

                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (SqlException e)
                    {
                        dataAccessStatus.setValues(status: "Error", operationSucceeded: false, exceptionMessage: e.Message,
                                                   customMessage: "Unable to Delete Department Model.",
                                                   helpLink: e.HelpLink, errorCode: e.ErrorCode, stackTrace: e.StackTrace);

                        throw new DataAccessException(e.Message, e.InnerException, dataAccessStatus);
                    }

                    //Confirm that the department model has been deleted

                    try
                    {
                        RecordExistsCheck(cmd, departmentModel, TypeOfExistenceCheck.DoesNotExistInDB, RequestType.ConfirmDelete);
                    }
                    catch (DataAccessException e)
                    {
                        e.DataAccessStatusInfo.Status             = "Error";
                        e.DataAccessStatusInfo.OperationSucceeded = false;
                        e.DataAccessStatusInfo.CustomMessage      = "Failed to delete Department model in database";
                        e.DataAccessStatusInfo.ExceptionMessage   = string.Copy(e.Message);
                        e.DataAccessStatusInfo.StackTrace         = string.Copy(e.StackTrace);

                        throw e;
                    }
                }
                sqlConnection.Close();
            }
        }
 public void ValidateDepartmentEmail(IDepartmentModel departmentModel)
 {
     throw new NotImplementedException();
 }
Beispiel #20
0
 internal static void PopulateWithRandomValues(IDepartmentModel record, DummyDataManager dtm, Random random)
 {
     record.Name = "TestDepartmentModel " + random.Next(1000000, 10000000);
 }
 public void ValidateModelFluentBuilder(IDepartmentModel departmentModel)
 {
     _modelValidationCheck.ValidateModelFluentBuilder <IDepartmentModel>(departmentModel, new DepartmentValidation());
 }
        public void Add(IDepartmentModel departmentModel)
        {
            DataAccessStatus dataAccessStatus = new DataAccessStatus();

            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                try
                {
                    sqlConnection.Open();
                }
                catch (SqlException e)
                {
                    dataAccessStatus.setValues(status: "Error", operationSucceeded: false, exceptionMessage: e.Message,
                                               customMessage: "Unable to add Department Model. Could not open a database connection", helpLink: e.HelpLink, errorCode: e.ErrorCode,
                                               stackTrace: e.StackTrace);

                    throw new DataAccessException(e.Message, e.InnerException, dataAccessStatus);
                }

                string addQuery =
                    "INSERT INTO [Departments] ([Name], PhoneNumber, ManagerID) " +
                    "VALUES (@DepartmentName, @PhoneNumber, @ManagerId)";

                using (SqlCommand cmd = new SqlCommand(null, sqlConnection))
                {
                    try
                    {
                        RecordExistsCheck(cmd, departmentModel, TypeOfExistenceCheck.DoesNotExistInDB, RequestType.Add);
                    }
                    catch (DataAccessException e)
                    {
                        e.DataAccessStatusInfo.CustomMessage    = "Department model could not be added because it is already in the database.";
                        e.DataAccessStatusInfo.ExceptionMessage = string.Copy(e.Message);
                        e.DataAccessStatusInfo.StackTrace       = string.Copy(e.StackTrace);

                        throw e;
                    }

                    cmd.CommandText = addQuery;

                    SqlParameter depName = new SqlParameter("@DepartmentName", System.Data.SqlDbType.VarChar, 40);
                    SqlParameter phone   = new SqlParameter("@PhoneNumber", System.Data.SqlDbType.VarChar, 20);
                    SqlParameter manID   = new SqlParameter("@ManagerId", System.Data.SqlDbType.Int);

                    depName.Value    = departmentModel.DepartmentName;
                    phone.Value      = departmentModel.PhoneNumber;
                    manID.IsNullable = true;


                    if (!(departmentModel.ManagerID == 0))
                    {
                        manID.Value = Convert.ToInt32((departmentModel.ManagerID));
                    }
                    else
                    {
                        manID.Value = DBNull.Value;
                    }
                    cmd.Parameters.Add(depName);
                    cmd.Parameters.Add(phone);
                    cmd.Parameters.Add(manID);



                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (SqlException e)
                    {
                        dataAccessStatus.setValues(status: "Error", operationSucceeded: false, exceptionMessage: e.Message,
                                                   customMessage: "Unable to add Department Model.", helpLink: e.HelpLink, errorCode: e.ErrorCode,
                                                   stackTrace: e.StackTrace);

                        throw new DataAccessException(e.Message, e.InnerException, dataAccessStatus);
                    }

                    //Confirm the Department Model was Added to the database
                    try
                    {
                        RecordExistsCheck(cmd, departmentModel, TypeOfExistenceCheck.DoesExistInDB, RequestType.ConfirmAdd);
                    }
                    catch (DataAccessException e)
                    {
                        e.DataAccessStatusInfo.Status             = "Error";
                        e.DataAccessStatusInfo.OperationSucceeded = false;
                        e.DataAccessStatusInfo.CustomMessage      = "Failed to find deaptment model in database after add o[eration completed.";
                        e.DataAccessStatusInfo.ExceptionMessage   = string.Copy(e.Message);
                        e.DataAccessStatusInfo.StackTrace         = string.Copy(e.StackTrace);

                        throw new DataAccessException(dataAccessStatus);
                    }

                    sqlConnection.Close();
                }
            }
        }
Beispiel #23
0
 public DepartmentRepositoryFixture(IUnitOfWork unitOfWork)
 {
     _departmentRepository = unitOfWork.Departments;
     _departmentModel      = new DepartmentModel();
 }
 public DepartmentServicesFixture(UnitOfWork unitOfWork)
 {
     _departmentServices = unitOfWork.DepartmentServices;
     _departmentModel    = new DepartmentModel();
 }
 public void ValidateModelDataAnnotations(IDepartmentModel departmentModel)
 {
     _modelDataAnnotationCheck.ValidateModelDataAnnotations(departmentModel);
 }
 public DepartmentServicesFixture()
 {
     this.departmentServices = new DepartmentServices(null, new ModelDataAnnotationCheck());
     this.departmentModel    = new DepartmentModel();
 }
        public void Update(IDepartmentModel departmentModel)
        {
            int result = -1;
            DataAccessStatus dataAccessStatus = new DataAccessStatus();

            using (SqlConnection sqlConnection = new SqlConnection(connectionString))
            {
                try
                {
                    sqlConnection.Open();
                }
                catch (SqlException e)
                {
                    dataAccessStatus.setValues(status: "Error", operationSucceeded: false, exceptionMessage: e.Message,
                                               customMessage: "Unable to Update Department Model. Could not open database connection.",
                                               helpLink: e.HelpLink, errorCode: e.ErrorCode, stackTrace: e.StackTrace);

                    throw new DataAccessException(e.Message, e.InnerException, dataAccessStatus);
                }

                string updateDepQuery =
                    "UPDATE [Departments]" +
                    "SET [Name] = @DepartmentName," +
                    "[PhoneNumber] = @PhoneNumber ," +
                    "[ManagerID] = @ManagerId " +
                    "WHERE [ID] =  @DepartmentId ";

                using (SqlCommand cmd = new SqlCommand(updateDepQuery, sqlConnection))
                {
                    try
                    {
                        RecordExistsCheck(cmd, departmentModel, TypeOfExistenceCheck.DoesExistInDB, RequestType.Update);
                    }
                    catch (DataAccessException e)
                    {
                        e.DataAccessStatusInfo.CustomMessage    = "Department model could not be updated because it could not be found in the database";
                        e.DataAccessStatusInfo.ExceptionMessage = string.Copy(e.Message);
                        e.DataAccessStatusInfo.StackTrace       = string.Copy(e.StackTrace);

                        throw e;
                    }

                    cmd.CommandText = updateDepQuery;

                    cmd.Parameters.Add("@DepartmentName", System.Data.SqlDbType.NVarChar, 40).Value = departmentModel.DepartmentName;
                    cmd.Parameters.Add("@PhoneNumber", System.Data.SqlDbType.NVarChar, 20).Value    = departmentModel.PhoneNumber;

                    if (!(departmentModel.ManagerID == 0))
                    {
                        cmd.Parameters.Add("@ManagerId", System.Data.SqlDbType.Int).Value = Convert.ToInt32(departmentModel.ManagerID);
                    }
                    else
                    {
                        cmd.Parameters.Add("@ManagerId", System.Data.SqlDbType.Int).Value = DBNull.Value;
                    }
                    cmd.Parameters.Add("@DepartmentId", System.Data.SqlDbType.Int).Value = Convert.ToInt32(departmentModel.DepartmentId);

                    cmd.Prepare();


                    try
                    {
                        result = cmd.ExecuteNonQuery();
                    }
                    catch (SqlException e)
                    {
                        dataAccessStatus.setValues(status: "Error", operationSucceeded: false, exceptionMessage: e.Message,
                                                   customMessage: "Unable to Update Department Model.",
                                                   helpLink: e.HelpLink, errorCode: e.ErrorCode, stackTrace: e.StackTrace);

                        throw new DataAccessException(e.Message, e.InnerException, dataAccessStatus);
                    }
                }
                sqlConnection.Close();
            }
        }
 public void ValidateDepartmentPhoneNumber(IDepartmentModel departmentModel)
 {
 }
 public void Remove(IDepartmentModel departmentModel)
 {
     departmentRepository.Remove(departmentModel);
 }