Esempio n. 1
0
        public BusinessObjectActionReport <DataRepositoryActionStatus> Update(IOfficeModel office)
        {
            BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success);

            businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(office);
            if (businessObjectActionReport.ValidationResult.IsValid)
            {
                int num;
                try
                {
                    using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext())
                        num = dataStoreContext.wm_Offices_Update(office);
                }
                catch (Exception ex)
                {
                    _Log.Error("Error at wm_Offices_Update", ex);
                    throw new DataStoreException(ex, true);
                }
                if (num == 0)
                {
                    businessObjectActionReport.Status = DataRepositoryActionStatus.NoRecordRowAffected;
                    _Log.ErrorFormat("Office {0} was not updated at the database, NoRecordRowAffected"
                                     , DebugUtility.GetObjectString(office));
                }
            }
            else
            {
                businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed;
                _Log.WarnFormat("Office {0} was not updated at the database because the validation failed.\nReport: {1}"
                                , DebugUtility.GetObjectString(office)
                                , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII));
            }
            return(businessObjectActionReport);
        }
Esempio n. 2
0
        internal static void Delete(IDataStore dataStore, IOfficeModel office)
        {
            OfficeManager manager = new OfficeManager(dataStore);

            int num = manager.Delete(office.ApplicationId, office.OfficeId);

            Assert.AreEqual(1, num);
            Assert.IsNull(manager.GetOffice(office.ApplicationId, office.OfficeId));

            Trace.WriteLine("Successfully deleted office " + office.Name);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public ActionResult Offices_Edit(int?officeId)
        {
            if (!officeId.HasValue)
            {
                return(RedirectToAction("PageNotFound", "Home"));
            }

            IOfficeModel record = InstanceContainer.OfficeManager.GetOffice(this.ApplicationId, officeId.Value);

            if (record == null)
            {
                return(RedirectToAction("PageNotFound", "Home"));
            }

            return(View(record));
        }
Esempio n. 5
0
        internal static void PopulateWithRandomValues(IOfficeModel record, DummyDataManager dtm, Random random)
        {
            record.AddressLine1 = DebugUtility.FlipCoin(random) ? dtm.GetDummyText(5, 32) : null;
            record.AddressLine2 = DebugUtility.FlipCoin(random) ? dtm.GetDummyText(5, 32) : null;
            record.AddressLine3 = DebugUtility.FlipCoin(random) ? dtm.GetDummyText(5, 32) : null;
            record.AddressLine4 = DebugUtility.FlipCoin(random) ? dtm.GetDummyText(5, 32) : null;

            record.ContactNumber = DebugUtility.FlipCoin(random) ? dtm.GetDummyText(5, 32) : null;
            record.Country       = DebugUtility.FlipCoin(random) ? dtm.GetDummyText(5, 32) : null;
            record.Description   = DebugUtility.FlipCoin(random) ? dtm.GetDummyText(5, 32) : null;
            record.Email         = DebugUtility.FlipCoin(random) ? dtm.GetDummyText(5, 32) : null;
            record.Fax           = DebugUtility.FlipCoin(random) ? dtm.GetDummyText(5, 32) : null;
            record.Location      = DebugUtility.FlipCoin(random) ? dtm.GetDummyText(5, 32) : null;
            record.PostCode      = DebugUtility.FlipCoin(random) ? dtm.GetDummyText(5, 8) : null;

            record.Name = "TestOfficeModel " + random.Next(1000000, 10000000);
        }
Esempio n. 6
0
        internal static IOfficeModel Create(IDataStore dataStore, IApplicationSettings applicationSettings, IApplication application
                                            , DummyDataManager dtm, Random random)
        {
            OfficeManager manager = new OfficeManager(dataStore);

            IOfficeModel office = new OfficeModel(
                application.ApplicationId
                , "OfficeName" + random.Next(1000000, 10000000));

            PopulateWithRandomValues(office, dtm, random);

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

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

            IOfficeModel dsOfficeModel = manager.GetOffice(office.ApplicationId, office.OfficeId);

            Assert.IsNotNull(dsOfficeModel);

            return(dsOfficeModel);
        }
Esempio n. 7
0
        public void Test_CreateUpdateDeleteOffice()
        {
            OfficeManager manager = new OfficeManager(this.DataStore);
            IOfficeModel  record  = Create(this.DataStore, Workmate.Components.InstanceContainer.ApplicationSettings, this.Application
                                           , this.DummyDataManager, this.Random);

            IOfficeModel recordToCompare;

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

                manager.Update(record);
                record = manager.GetOffice(record.ApplicationId, record.OfficeId);

                string errors = string.Empty;

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

            Delete(this.DataStore, record);
        }
Esempio n. 8
0
        public BusinessObjectActionReport <DataRepositoryActionStatus> Create(int applicationId, IOfficeModel office)
        {
            BusinessObjectActionReport <DataRepositoryActionStatus> businessObjectActionReport = new BusinessObjectActionReport <DataRepositoryActionStatus>(DataRepositoryActionStatus.Success);

            businessObjectActionReport.ValidationResult = BusinessObjectManager.Validate(office);
            if (businessObjectActionReport.ValidationResult.IsValid)
            {
                int num;
                try
                {
                    using (IDataStoreContext dataStoreContext = this._DataStore.CreateContext())
                        num = dataStoreContext.wm_Offices_Insert(applicationId, office);
                }
                catch (Exception ex)
                {
                    _Log.Error("Error at wm_Offices_Insert", ex);
                    throw new DataStoreException(ex, true);
                }
                if (num <= 0)
                {
                    businessObjectActionReport.Status = DataRepositoryActionStatus.SqlError;
                    _Log.ErrorFormat("Office {0} was not inserted at the database (ErrorCode: {1})."
                                     , DebugUtility.GetObjectString(office)
                                     , num);
                }
                else
                {
                    office.OfficeId = num;
                }
            }
            else
            {
                businessObjectActionReport.Status = DataRepositoryActionStatus.ValidationFailed;
                _Log.WarnFormat("Office {0} was not inserted at the database because the validation failed.\nReport: {1}"
                                , DebugUtility.GetObjectString(office)
                                , businessObjectActionReport.ValidationResult.ToString(TextFormat.ASCII));
            }
            return(businessObjectActionReport);
        }