/// <summary>
        /// Method to load the resource information based on job id and resource id
        /// </summary>
        public void LoadResources()
        {
            using (ResourceAllocationModel _resourceAllocationModel = new ResourceAllocationModel())
            {
                IList<CS_Resource> lstResource = new List<CS_Resource>();

                if (_view.ResourceTransferId.Count > 0)
                {
                    CS_Resource resource = new CS_Resource();

                    _view.HasEquipments = false;
                    for (int i = 0; i < _view.ResourceTransferId.Count; i++)
                    {
                        resource = _resourceAllocationModel.GetResourceByJobAndResourceId(_view.JobId, _view.ResourceTransferId[i]);

                        if (resource.EquipmentID.HasValue)
                            _view.HasEquipments = true;

                        if (null != resource)
                            lstResource.Add(resource);
                    }
                }

                if (lstResource.Count > 0)
                {
                    _view.ResourceListDataSource = lstResource;
                    _view.SelectedResources = lstResource.ToList();
                }
            }
        }
 public void TestGetResource()
 {
     //Arrange
     ResourceAllocationModel model = new ResourceAllocationModel(new FakeUnitOfWork());
     //Act
     CS_Resource resource = model.GetResource(1);
     //Assert
     Assert.IsNotNull(resource);
 }
 /// <summary>
 /// Class Constructor
 /// </summary>
 /// <param name="view">Instance of the Permit Info View Interface</param>
 public JobInfoPresenter(IJobInfoView view)
 {
     this._view = view;
     this._jobModel = new JobModel();
     this._divisionModel = new DivisionModel();
     this._customerModel = new CustomerModel();
     this._employeeModel = new EmployeeModel();
     _resourceAllocationModel = new ResourceAllocationModel();
 }
        public void TestClearReservesByJobId()
        {
            //Arrange
            FakeObjectSet<CS_Reserve> fakeReserveList = new FakeObjectSet<CS_Reserve>();
            fakeReserveList.AddObject
            (
                new CS_Reserve()
                    {
                        ID = 1,
                        Active = true,
                        CreateBy = "Load",
                        CreationDate = DateTime.Now,
                        DivisionID = 1,
                        Duration = 1,
                        EmployeeID = 1,
                        EquipmentTypeID = 1,
                        JobID = 1,
                        ModificationDate = DateTime.Now,
                        ModifiedBy = "Load",
                        StartDateTime = DateTime.Now,
                        Type = 1
                    }
            );
            fakeReserveList.AddObject
            (
                new CS_Reserve()
                {
                    ID = 2,
                    Active = true,
                    CreateBy = "Load",
                    CreationDate = DateTime.Now,
                    DivisionID = 1,
                    Duration = 1,
                    EquipmentTypeID = 1,
                    JobID = 1,
                    ModificationDate = DateTime.Now,
                    ModifiedBy = "Load",
                    StartDateTime = DateTime.Now,
                    Type = 1
                }
            );

            Mock<IUnitOfWork> mockUnitOfWork = new Mock<IUnitOfWork>();
            mockUnitOfWork.Setup(w => w.CreateObjectSet<CS_Reserve>()).Returns(fakeReserveList);

            //Act
            ResourceAllocationModel model = new ResourceAllocationModel(mockUnitOfWork.Object);

            IList<CS_Reserve> reserveList = model.ClearReservesByJobId(1, "rbrandao");

            //Assert
            for (int i = 0; i < reserveList.Count; i++)
            {
                Assert.AreEqual(reserveList[i].Active, false);
            }
        }
        public ResourceAllocationViewModel(IResourceAllocationView view)
        {
            _view = view;

            _equipmentModel = new EquipmentModel();
            _divisionModel = new DivisionModel();
            _employeeModel = new EmployeeModel();
            _resourceAllocationModel = new ResourceAllocationModel();
            _locationModel = new LocationModel();
            _jobModel = new JobModel();
            _callLogModel = new CallLogModel();

            _divisionNumber = string.Empty;
            _name = string.Empty;
            _type = Globals.ResourceAllocation.Type.AddEmployee;
        }
 public void TestListAllFilteredResourcesInfoByJob()
 {
     //Arrange
     ResourceAllocationModel model = new ResourceAllocationModel(new FakeUnitOfWork());
     //Act
     IList<CS_View_Resource_CallLogInfo> resultList = model.ListFilteredResourcesCallLogInfoByJob(5, true,true,null, null);
     //Assert
     Assert.AreEqual(2, resultList.Count);
 }
        public void TestUpdateResourceAllocation()
        {
            //Arrange
            IList<CS_Resource> resourceList = new List<CS_Resource>(){
                new CS_Resource() {
                    Active = true, CreatedBy = "Load", CreationDate = DateTime.Now, Description = "DescriptionTest",
                    Duration=1, EmployeeID = 1, EquipmentID =1, JobID = 1, ModificationDate = DateTime.Now,
                    ModifiedBy = "Load", StartDateTime = DateTime.Now, Type = 1,
                    CS_Equipment = new CS_Equipment(){
                        Name ="Sideboom",
                        CS_Division = new CS_Division() { ID = 1, Name = "no name", Active = true }
                    },
                    CS_Employee = new CS_Employee() { Name="Ruziska", FirstName="Danilo" }
                },
                new CS_Resource() {
                    Active = true, CreatedBy = "Load", CreationDate = DateTime.Now, Description = "DescriptionTest2",
                    Duration=1, EmployeeID = 1, EquipmentID =1, JobID = 1, ModificationDate = DateTime.Now,
                    ModifiedBy = "Load", StartDateTime = DateTime.Now, Type = 1,
                    CS_Equipment = new CS_Equipment(){
                        Name ="Sideboom",
                        CS_Division = new CS_Division() { ID = 1, Name = "no name", Active = true }
                    },
                    CS_Employee = new CS_Employee() { Name="Ruziska", FirstName="Danilo" }
                }
            };

            IList<CS_Reserve> reserveList = new List<CS_Reserve>(){
                new CS_Reserve() {
                    Active = true, CreateBy = "Load", CreationDate = DateTime.Now, DivisionID = 1, Duration = 1,
                    EmployeeID = 1, EquipmentTypeID = 1, JobID = 1, ModificationDate = DateTime.Now, ModifiedBy = "Load",
                    StartDateTime = DateTime.Now, Type = 1,
                    CS_EquipmentType = new CS_EquipmentType() { ID = 1, Name = "no name", Active = true },
                    CS_Division = new CS_Division() { ID = 1, Name = "no name", Active = true }
                },
                new CS_Reserve() {
                    Active = true, CreateBy = "Load", CreationDate = DateTime.Now, DivisionID = 1, Duration = 1,
                    EmployeeID = 1, EquipmentTypeID = null, JobID = 1, ModificationDate = DateTime.Now, ModifiedBy = "Load",
                    StartDateTime = DateTime.Now, Type = 1,
                    CS_Employee = new CS_Employee() {
                        ID = 1, Name = "no name", Active = true,
                        CS_Division = new CS_Division() { ID = 1, Name = "no name", Active = true }
                    }
                }
            };

            IList<int> lstDivisions = new List<int>();
            lstDivisions.Add(2);

            FakeObjectSet<CS_Resource> fakeResourceList = new FakeObjectSet<CS_Resource>();
            FakeObjectSet<CS_Reserve> fakeReserveList = new FakeObjectSet<CS_Reserve>();
            FakeObjectSet<CS_EquipmentPermit> fakePermitList = new FakeObjectSet<CS_EquipmentPermit>();
            FakeObjectSet<CS_CallLog> fakeCallLogList = new FakeObjectSet<CS_CallLog>();
            FakeObjectSet<CS_CallLogResource> fakeCallLogResourceList = new FakeObjectSet<CS_CallLogResource>();
            FakeObjectSet<CS_CallType> fakeCallTypeList = new FakeObjectSet<CS_CallType>();
            fakeCallTypeList.AddObject(new CS_CallType() { ID = 1, Active = true });

            Mock<IUnitOfWork> mockUnitOfWork = new Mock<IUnitOfWork>();
            mockUnitOfWork.Setup(e => e.CreateObjectSet<CS_Resource>()).Returns(fakeResourceList);
            mockUnitOfWork.Setup(e => e.CreateObjectSet<CS_Reserve>()).Returns(fakeReserveList);
            mockUnitOfWork.Setup(e => e.CreateObjectSet<CS_EquipmentPermit>()).Returns(fakePermitList);
            mockUnitOfWork.Setup(e => e.CreateObjectSet<CS_CallLog>()).Returns(fakeCallLogList);
            mockUnitOfWork.Setup(e => e.CreateObjectSet<CS_CallLogResource>()).Returns(fakeCallLogResourceList);
            mockUnitOfWork.Setup(e => e.CreateObjectSet<CS_CallType>()).Returns(fakeCallTypeList);

            //Act
            ResourceAllocationModel model = new ResourceAllocationModel(mockUnitOfWork.Object);
            model.SaveOrUpdateResourceAllocation(1, reserveList, resourceList, "druziska", lstDivisions, string.Empty, false, DateTime.Now, false, string.Empty, string.Empty);

            //Assert
            Assert.IsNotNull(model.ResourceSaved);
            Assert.IsNotNull(model.ReserveSaved);
        }
        public void TestSaveResourceAllocation()
        {
            //Arrange
            IList<CS_Resource> resourceList = new List<CS_Resource>(){
                new CS_Resource() { ID=1, Active = true, CreatedBy = "Load", CreationDate = DateTime.Now, Description = "DescriptionTest", Duration=1, EmployeeID = 1, EquipmentID =1,
                    JobID = 1, ModificationDate = DateTime.Now, ModifiedBy = "Load", StartDateTime = DateTime.Now, Type = 1 },
                new CS_Resource() { ID = 1, Active = true, CreatedBy = "Load", CreationDate = DateTime.Now, Description = "DescriptionTest2", Duration=1, EmployeeID = 1, EquipmentID =1,
                JobID = 1, ModificationDate = DateTime.Now, ModifiedBy = "Load", StartDateTime = DateTime.Now, Type = 1 }
            };

            IList<CS_Reserve> reserveList = new List<CS_Reserve>(){
                new CS_Reserve() { ID = 1, Active =true, CreateBy = "Load", CreationDate=DateTime.Now, DivisionID = 1, Duration = 1, EmployeeID = 1, EquipmentTypeID = 1, JobID = 1,
                    ModificationDate = DateTime.Now, ModifiedBy = "Load", StartDateTime = DateTime.Now, Type = 1  },
                new CS_Reserve() { ID = 1, Active =true, CreateBy = "Load", CreationDate=DateTime.Now, DivisionID = 1, Duration = 1, EmployeeID = 1, EquipmentTypeID = 1, JobID = 1,
                ModificationDate = DateTime.Now, ModifiedBy = "Load", StartDateTime = DateTime.Now, Type = 1  }
            };

            IList<int> lstDivisions = new List<int>();
            lstDivisions.Add(2);

            //Act
            ResourceAllocationModel model = new ResourceAllocationModel(new FakeUnitOfWork());
            model.SaveOrUpdateResourceAllocation(1, reserveList, resourceList, "druziska", lstDivisions, string.Empty, false, DateTime.Now, false, string.Empty,string.Empty);

            //Assert
            Assert.IsNotNull(model.ResourceSaved);
            Assert.IsNotNull(model.ReserveSaved);
        }
        public void TransferResources()
        {
            using (_jobModel = new JobModel())
            {
                CS_JobStatus jobStatus = _jobModel.GetJobById(_view.JobIdTo).CS_JobInfo.LastJobStatus;

                if (null == jobStatus || (null != jobStatus && jobStatus.ID != (int)Globals.JobRecord.JobStatus.Active))
                {
                    _view.DisplayMessage("Resources cannot be transfered to an inactive job.", false);
                    return;
                }
            }

            using (ResourceAllocationModel _resourceAllocationModel = new ResourceAllocationModel())
            {
                if (_view.SelectedResources.Count > 0)
                {
                    List<CS_Resource> newJobResourceSelection = CopyResourcesToNewList(_view.SelectedResources, _view.JobIdTo);
                    _resourceAllocationModel.TransferResources(_view.SelectedResources, newJobResourceSelection, _view.SelectedResourcesTransferType, _view.SelectedCallLogIds, _view.JobId, _view.JobIdTo, _view.Username);

                    _view.DisplayMessage("Resources transfered successfully!", true);
                }
                else
                {
                    _view.DisplayMessage("There was an error loading the resources for transfer, please try opening the page again.", true);
                }
            }
        }
 public void GetMapPlottingObjects()
 {
     try
     {
         List<Globals.MapPlotDataObject> returnList = new List<Globals.MapPlotDataObject>();
         using (_jobModel = new JobModel())
         {
             returnList.AddRange(_jobModel.FilterMapPlotting(_view.MapPlottingFilter));
         }
         using (_resourceAllocationModel = new ResourceAllocationModel())
         {
             returnList.AddRange(_resourceAllocationModel.FilterMapPlotting(_view.MapPlottingFilter));
         }
         _view.MapPlottingObjectsList = returnList;
     }
     catch (Exception ex)
     {
         if (null != ex.InnerException)
             Logger.Write(string.Format("An error has occurred while trying to get the Map Plot List\n{0}\n{1}\n{2}\n{3}", ex.Message, ex.StackTrace, ex.InnerException.Message, ex.InnerException.StackTrace));
         else
             Logger.Write(string.Format("An error has occurred while trying to get the Map Plot List\n{0}\n{1}", ex.Message, ex.StackTrace));
     }
 }
 public void ListResourceAssignedFilterOptions()
 {
     try
     {
         using (_resourceAllocationModel = new ResourceAllocationModel())
         {
             _view.ResourceAssignedFilterValues = _resourceAllocationModel.ListResourcesAssignedFilterValues(_view.SelectedCallType.ShowEmployee.Value, _view.SelectedCallType.ShowEquipment.Value);
         }
     }
     catch (Exception ex)
     {
         Logger.Write(string.Format("An Error has ocurred while trying to Filter the resources.\n{0}\n{1}", ex.Message, ex.StackTrace));
         _view.DisplayMessage("An Internal Error has ocurred while trying to Filter the resources. Please try again.", false);
     }
 }
 /// <summary>
 /// List all Resources related to a specific job record
 /// </summary>
 public void ListAllFilteredResourcesCallLogInfoInfoByJob()
 {
     try
     {
         using (_resourceAllocationModel = new ResourceAllocationModel())
         {
             _view.ResourceGridDataSource = _resourceAllocationModel.ListFilteredResourcesCallLogInfoByJob(_view.JobId.Value, _view.SelectedCallType.ShowEmployee.Value, _view.SelectedCallType.ShowEquipment.Value, _view.ResourceFilterType, _view.ResourceFilterValue);
         }
     }
     catch (Exception ex)
     {
         Logger.Write(string.Format("An Error has ocurred while trying to Filter the resources.\n{0}\n{1}", ex.Message, ex.StackTrace));
         _view.DisplayMessage("An Internal Error has ocurred while trying to Filter the resources. Please try again.", false);
     }
 }
 /// <summary>
 /// List all resources already assigned to a call log
 /// </summary>
 public void ListAddedResource()
 {
     try
     {
         using (_resourceAllocationModel = new ResourceAllocationModel())
         {
             _view.SelectedResources = _resourceAllocationModel.ListAddedResource(_view.CallID.Value, (int)Globals.CallEntry.CallLogResourceType.Equipment);
         }
     }
     catch (Exception ex)
     {
         Logger.Write(string.Format("An Error has ocurred while trying to List Resources.\n{0}\n{1}", ex.Message, ex.StackTrace));
         _view.DisplayMessage("An Internal Error has ocurred while trying to load the Information. Please try again.", false);
     }
 }
 /// <summary>
 /// Add resources to a selected resources list
 /// </summary>
 public void AddResourceToCallEntry()
 {
     try
     {
         using (_resourceAllocationModel = new ResourceAllocationModel())
         {
             _view.SelectedResources.Add(_resourceAllocationModel.GetResource(_view.SelectedResourceId));
         }
     }
     catch (Exception ex)
     {
         Logger.Write(string.Format("An Error has ocurred while trying to AddResourceToCallEntry.\n{0}\n{1}", ex.Message, ex.StackTrace));
         _view.DisplayMessage("An Internal Error has ocurred while trying to load the Information. Please try again.", false);
     }
 }