/// <summary> /// Get all the lists from InterventionType table /// </summary> /// <returns></returns> public List <InterventionType> GetInterventionTypeList() { List <InterventionType> aInterventionTypeList = new List <InterventionType>(); connectionString = aDatabaseConfig.Setup("ENETCareDatabase"); using (SqlConnection connection = new SqlConnection()) { connection.ConnectionString = connectionString; string query = "SELECT * FROM [Intervention Type]"; SqlCommand command = new SqlCommand(query, connection); try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { InterventionType aInterventionType = new InterventionType(); aInterventionType.InterventionTypeID = Int32.Parse(reader["InterventionTypeID"].ToString()); aInterventionType.InterventionTypeName = reader["InterventionTypeName"].ToString(); aInterventionType.EstimatedLabour = double.Parse(reader["EstimatedLabour"].ToString()); aInterventionType.EstimatedCost = double.Parse(reader["EstimatedCost"].ToString()); aInterventionTypeList.Add(aInterventionType); } } catch { } } return(aInterventionTypeList); }
private void SelectATypeOfIntervention() { InterventionType.Click(); PageHelper.PickRandomValueFromDropList(InterventionTypeList, new List <string> { "Not Aplicable" }); }
void ChangeModivation(InterventionType type) { switch (type) { case InterventionType.InfoCryptic: { isCurious = true; break; } case InterventionType.InfoDirect: { isCurious = false; break; } case InterventionType.Weapon: { isBrave = true; break; } case InterventionType.Trap: { isBrave = false; break; } } }
public void CreateIntervention_OnApprovedStateWithInsufficientMaxLabourHours_ReturnNullAndFalse() { bool result = false; string msg = ""; InterventionType type = new InterventionType { DefaultCost = 10000, DefaultLabourHours = 100, InterventionTypeId = 1, Name = "Supply and Install Portable Toilet" }; Client client = new Client { Address = "Pitt St", ClientId = 1, District = "Rural Indonesia", Name = "John Lennon" }; ENETCareGlobal.CurrentUser = new SiteEngineer { District = "Rural Indonesia", MaxHours = 1, MaxCost = 10000, Name = "Neil", SiteEngineerId = 1, UserId = 1 }; DateTime dateToPerform = new DateTime(2991, 9, 23); Intervention intervention = new InterventionManager().CreateIntervention(type, "Approved", 100, 10000, "OK", dateToPerform, client, out msg, out result); Assert.IsFalse(result); Assert.IsNull(intervention); }
protected void CreateBtn_Click(object sender, EventArgs e) { InterventionType selectedType = null; foreach (InterventionType type in ENETCareGlobal.allInterventionTypes) { if (type.Name == InterventionTypeDropDownList.SelectedValue) { selectedType = type; } } int labourHours = -1; int.TryParse(LabourHoursTextBox.Text, out labourHours); decimal cost = -1; decimal.TryParse(CostTextBox.Text, out cost); if (DateToPerformTextBox.Text != "") { if (NoteTextBox.Text.Length < 100) { DateTime dt = Convert.ToDateTime(DateToPerformTextBox.Text); bool result = false; string msg = ""; if (Session["selectedClientIdx"] != null) { Intervention newIntervention = new InterventionManager().CreateIntervention(selectedType, StateDropDownList.SelectedValue, labourHours, cost, NoteTextBox.Text, dt, ENETCareGlobal.allClients[(int)Session["selectedClientIdx"]], out msg, out result); if (result) { new InterventionRepository().Insert(newIntervention); ErrorLabel.Text = "Success!"; } else { ErrorLabel.Text = msg; } } else { ErrorLabel.Text = "Please select a client!"; } } else { ErrorLabel.Text = "Note too long, character limit is 100"; } } else { ErrorLabel.Text = "Please select a date!"; } }
public InterventionType create(InterventionType interventionType) { using (IMSEntities context = new IMSEntities()) { context.InterventionTypes.Add(new InterventionType(interventionType)); context.SaveChanges(); return(context.InterventionTypes.Find(interventionType)); } }
/// <summary> /// Create an intervention type /// </summary> /// <param name="interventionType">Intervention type object</param> /// <returns>An intervention type object created</returns> public InterventionType create(InterventionType interventionType) { SqlCommand command = new SqlCommand(@"INSERT INTO InterventionTypes (Name, Hours, Costs) VALUES(@Name, @Hours, @Costs)"); interventionType.Id = (Guid)sqlExecuter.ExecuteScalar(command, interventionType); if (interventionType.Id != Guid.Empty) { return(interventionType); } return(null); }
public void IMSLogicSiteEngineer_ApproveIntervention_Success() { Intervention intervention = new Intervention(5, 20, 5, "", IMSLogicLayer.Enums.InterventionState.Proposed, new DateTime(), new DateTime(), new DateTime(), new Guid(), new Guid(), createdBy: engineer_a_ID, approvedBy: new Guid()); InterventionType interventionType = new InterventionType("toilet", 5, 20); District district = new District("Asquith") { Id = new Guid() }; Client client = new Client("", "", new Guid()) { DistrictId = district.Id, }; User engineer = new User("me", 1, 500, 20000, "", new Guid()) { DistrictId = district.Id, Id = engineer_a_ID }; Mock <IInterventionDataAccess> interventions = new Mock <IInterventionDataAccess>(); interventions.Setup(i => i.fetchInterventionsById(It.IsAny <Guid>())).Returns(intervention); Mock <IInterventionTypeDataAccess> interventionTypes = new Mock <IInterventionTypeDataAccess>(); interventionTypes.Setup(its => its.fetchInterventionTypesById(It.IsAny <Guid>())).Returns(interventionType); Mock <IDistrictDataAccess> districts = new Mock <IDistrictDataAccess>(); districts.Setup(d => d.fetchDistrictById(It.IsAny <Guid>())).Returns(district); Mock <IClientDataAccess> clients = new Mock <IClientDataAccess>(); clients.Setup(c => c.fetchClientById(It.IsAny <Guid>())).Returns(client); Mock <IUserDataAccess> users = new Mock <IUserDataAccess>(); users.Setup(u => u.fetchUserByIdentityId(It.IsAny <Guid>())).Returns(engineer); users.Setup(u => u.fetchUserById(It.IsAny <Guid>())).Returns(engineer); Mock <IInterventionService> interventionService = new Mock <IInterventionService>(); interventionService.Setup(i => i.updateInterventionState(It.IsAny <Guid>(), IMSLogicLayer.Enums.InterventionState.Approved, engineer.Id)).Returns(true); interventionService.Setup(i => i.updateIntervetionApprovedBy(It.IsAny <Guid>(), It.IsAny <User>())).Returns(true); engineerService.Interventions = interventions.Object; engineerService.InterventionTypes = interventionTypes.Object; engineerService.Districts = districts.Object; engineerService.Clients = clients.Object; engineerService.Users = users.Object; engineerService.InterventionService = interventionService.Object; Assert.IsTrue(engineerService.approveAnIntervention(intervention.Id)); }
public void Given_InterventionTypeName_Is_Valid_ExpectNoValidationError() { var model = new InterventionType() { InterventionTypeName = "Mosquito Net", EstimatedCost = 2000, EstimatedLabour = 24, }; var ErrorMeassageList = TestModelHelper.Validate(model); Assert.AreEqual(0, ErrorMeassageList.Count); }
public bool update(InterventionType interventionType) { using (IMSEntities context = new IMSEntities()) { var old = context.InterventionTypes.Where(i => i.Id == interventionType.Id).FirstOrDefault(); context.Entry(old).CurrentValues.SetValues(interventionType); if (context.SaveChanges() > 0) { return(true); } return(false); } }
public void GetInterventionTypeDataTest() { InterventionType intertype = new InterventionType(); intertype.InterventionTypeId = 1; intertype.InterventionTypeName = "First Aid Kit"; mockUserDao = new Mock <IUserDao>(); mockInterDao = new Mock <IInterventionsDao>(); mockInterDao.Setup(p => p.GetInterventionType(intertype.InterventionTypeId)).Returns(intertype); InterventionHelper_UnderTest = new SiteEngineerHelper(mockUserDao.Object, mockInterDao.Object); var inter = InterventionHelper_UnderTest.GetInterventionTypeData(intertype.InterventionTypeId); Assert.AreEqual(intertype.InterventionTypeName, inter.InterventionTypeName); }
public void Given_InterventionTypeName_Is_Null_ExpectOneValidationError() { var model = new InterventionType() { InterventionTypeName = "", EstimatedCost = 2000, EstimatedLabour = 24, }; var ErrorMeassageList = TestModelHelper.Validate(model); Assert.AreEqual(1, ErrorMeassageList.Count); Assert.AreEqual("The Intervention Type Name field is required.", ErrorMeassageList[0].ErrorMessage); }
/// <summary> /// the supporting function that setup the requirements for ApproveIntervention related tests /// </summary> /// <returns>the guid of the generated intervention</returns> private Guid IMSLogicManager_ApproveInterventionTests_Setup() { Mock <IInterventionDataAccess> interventions = new Mock <IInterventionDataAccess>(); Intervention intervention = new Intervention(5, 50, 1, "", IMSLogicLayer.Enums.InterventionState.Proposed, new DateTime(), new DateTime(), new DateTime(), new Guid(), new Guid(), new Guid(), null); interventions.Setup(i => i.fetchInterventionsById(It.IsAny <Guid>())).Returns(intervention); Mock <IInterventionTypeDataAccess> interventionTypes = new Mock <IInterventionTypeDataAccess>(); InterventionType interventionType = new InterventionType("toilet", 5, 50); interventionTypes.Setup(it => it.fetchInterventionTypesById(It.IsAny <Guid>())).Returns(interventionType); managerService.Interventions = interventions.Object; managerService.InterventionTypes = interventionTypes.Object; return(intervention.Id); }
public List <InterventionType> GetAll(string whereClause) { StringBuilder sqlStr = new StringBuilder(); sqlStr.Append("SELECT *"); sqlStr.Append(" FROM InterventionType "); if (whereClause.Trim() != "") { sqlStr.Append(" WHERE " + whereClause); } List <InterventionType> models = new List <InterventionType>(); DataTable dataTable = SQLHelper.Select(sqlStr.ToString()).Tables[0]; int rowsCount = dataTable.Rows.Count; if (rowsCount > 0) { for (int n = 0; n < rowsCount; n++) { InterventionType interventionType = new InterventionType(); if (dataTable.Rows[n]["InterventionTypeId"].ToString() != "") { interventionType.InterventionTypeId = int.Parse(dataTable.Rows[n]["InterventionTypeId"].ToString()); } if (dataTable.Rows[n]["Name"].ToString() != "") { interventionType.Name = dataTable.Rows[n]["Name"].ToString(); } if (dataTable.Rows[n]["Cost"].ToString() != "") { interventionType.DefaultCost = decimal.Parse(dataTable.Rows[n]["Cost"].ToString()); } if (dataTable.Rows[n]["LabourHours"].ToString() != "") { interventionType.DefaultLabourHours = int.Parse(dataTable.Rows[n]["LabourHours"].ToString()); } models.Add(interventionType); } } return(models); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { InterventionType.DataSource = CreateInterventionTypeDataSource(); InterventionType.DataTextField = "InterventionType"; InterventionType.DataValueField = "InterventionTypeId"; InterventionType.DataBind(); InterventionType.SelectedIndex = 0; ClientName.DataSource = CreateClientNameDataSource(); ClientName.DataTextField = "ClientName"; ClientName.DataValueField = "ClientId"; ClientName.DataBind(); ClientName.SelectedIndex = 0; ChangeHoursCostText(); } else { ErrorMessage.Visible = false; } }
private void CreateInterventionType() { var factory = new DbConnectionFactory("CustomDatabase"); var context = new DbContext(factory); var repos = new InterventionTypeRepository(context); var interventionType = new InterventionType(); var rows = repos.GetAll(); if (rows.Count == 0) { interventionType.InterventionTypeName = "Supply and Install Portable Toilet"; interventionType.InterventionTypeHours = 10; interventionType.InterventionTypeCost = 200; repos.Insert(interventionType); interventionType.InterventionTypeName = "Hepatitis Avoidance Training"; interventionType.InterventionTypeHours = 15; interventionType.InterventionTypeCost = 300; repos.Insert(interventionType); interventionType.InterventionTypeName = "Supply and Install Storm-proof Home Kit"; interventionType.InterventionTypeHours = 50; interventionType.InterventionTypeCost = 500; repos.Insert(interventionType); } }
private async Task CreateUser(CustomDBContext context) { var userStore = new UserStore <ApplicationUser>(new ApplicationDbContext()); var userManager = new UserManager <ApplicationUser>(userStore); User user; IList <User> users = new List <User>(); InterventionType interventionType; IList <InterventionType> interventionTypes = new List <InterventionType>(); var count = await context.InterventionTypes.CountAsync(); if (count == 0) { interventionType = new InterventionType(); interventionType.InterventionTypeName = "Supply and Install Portable Toilet"; interventionType.InterventionTypeHours = 10; interventionType.InterventionTypeCost = 200; interventionTypes.Add(interventionType); interventionType = new InterventionType(); interventionType.InterventionTypeName = "Hepatitis Avoidance Training"; interventionType.InterventionTypeHours = 15; interventionType.InterventionTypeCost = 300; interventionTypes.Add(interventionType); interventionType = new InterventionType(); interventionType.InterventionTypeName = "Supply and Install Storm-proof Home Kit"; interventionType.InterventionTypeHours = 50; interventionType.InterventionTypeCost = 500; interventionTypes.Add(interventionType); } var findAccountant = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findAccountant)) { user = new User(); user.UserId = findAccountant.Id; user.MaximumHours = 1000; user.MaximumCost = 50000; user.District = Districts.URBAN_INDONESIA; users.Add(user); } var findManager = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findManager)) { user = new User(); user.UserId = findManager.Id; user.MaximumHours = 100; user.MaximumCost = 5000; user.District = Districts.URBAN_INDONESIA; users.Add(user); } var findManagerYamin = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findManagerYamin)) { user = new User(); user.UserId = findManagerYamin.Id; user.MaximumHours = 100; user.MaximumCost = 5000; user.District = Districts.URBAN_INDONESIA; users.Add(user); } var findSiteEngineer = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findSiteEngineer)) { user = new User(); user.UserId = findSiteEngineer.Id; user.MaximumHours = 50; user.MaximumCost = 2000; user.District = Districts.URBAN_INDONESIA; users.Add(user); } var findSiteEngineerYamin = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findSiteEngineerYamin)) { user = new User(); user.UserId = findSiteEngineerYamin.Id; user.MaximumHours = 50; user.MaximumCost = 2000; user.District = Districts.URBAN_INDONESIA; users.Add(user); } var findSiteEngineer2 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findSiteEngineer2)) { user = new User(); user.UserId = findSiteEngineer2.Id; user.MaximumHours = 25; user.MaximumCost = 1000; user.District = Districts.URBAN_INDONESIA; users.Add(user); } var findManager2 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findManager2)) { user = new User(); user.UserId = findManager2.Id; user.MaximumHours = 100; user.MaximumCost = 5000; user.District = Districts.RURAL_INDONESIA; users.Add(user); } var findSiteEngineer3 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findSiteEngineer3)) { user = new User(); user.UserId = findSiteEngineer3.Id; user.MaximumHours = 50; user.MaximumCost = 2000; user.District = Districts.RURAL_INDONESIA; users.Add(user); } var findSiteEngineer4 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findSiteEngineer4)) { user = new User(); user.UserId = findSiteEngineer4.Id; user.MaximumHours = 25; user.MaximumCost = 1000; user.District = Districts.RURAL_INDONESIA; users.Add(user); } var findManager3 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findManager3)) { user = new User(); user.UserId = findManager3.Id; user.MaximumHours = 100; user.MaximumCost = 5000; user.District = Districts.URBAN_PAPUA_NEW_GUINEA; users.Add(user); } var findSiteEngineer5 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findSiteEngineer5)) { user = new User(); user.UserId = findSiteEngineer5.Id; user.MaximumHours = 50; user.MaximumCost = 2000; user.District = Districts.URBAN_PAPUA_NEW_GUINEA; users.Add(user); } var findSiteEngineer6 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findSiteEngineer6)) { user = new User(); user.UserId = findSiteEngineer6.Id; user.MaximumHours = 25; user.MaximumCost = 1000; user.District = Districts.URBAN_PAPUA_NEW_GUINEA; users.Add(user); } var findManager4 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findManager4)) { user = new User(); user.UserId = findManager4.Id; user.MaximumHours = 100; user.MaximumCost = 5000; user.District = Districts.RURAL_PAPUA_NEW_GUINEA; users.Add(user); } var findSiteEngineer7 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findSiteEngineer7)) { user = new User(); user.UserId = findSiteEngineer7.Id; user.MaximumHours = 50; user.MaximumCost = 2000; user.District = Districts.RURAL_PAPUA_NEW_GUINEA; users.Add(user); } var findSiteEngineer8 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findSiteEngineer8)) { user = new User(); user.UserId = findSiteEngineer8.Id; user.MaximumHours = 25; user.MaximumCost = 1000; user.District = Districts.RURAL_PAPUA_NEW_GUINEA; users.Add(user); } var findManager5 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findManager5)) { user = new User(); user.UserId = findManager5.Id; user.MaximumHours = 100; user.MaximumCost = 5000; user.District = Districts.SYDNEY; users.Add(user); } var findSiteEngineer9 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findSiteEngineer9)) { user = new User(); user.UserId = findSiteEngineer9.Id; user.MaximumHours = 50; user.MaximumCost = 2000; user.District = Districts.SYDNEY; users.Add(user); } var findSiteEngineer10 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findSiteEngineer10)) { user = new User(); user.UserId = findSiteEngineer10.Id; user.MaximumHours = 25; user.MaximumCost = 1000; user.District = Districts.SYDNEY; users.Add(user); } var findManager6 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findManager6)) { user = new User(); user.UserId = findManager6.Id; user.MaximumHours = 100; user.MaximumCost = 5000; user.District = Districts.RURAL_NEW_SOUTH_WALES; users.Add(user); } var findSiteEngineer11 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findSiteEngineer11)) { user = new User(); user.UserId = findSiteEngineer11.Id; user.MaximumHours = 50; user.MaximumCost = 2000; user.District = Districts.RURAL_NEW_SOUTH_WALES; users.Add(user); } var findSiteEngineer12 = await userManager.FindByEmailAsync("*****@*****.**"); if (!Utils.getInstance.isNullOrEmpty(findSiteEngineer12)) { user = new User(); user.UserId = findSiteEngineer12.Id; user.MaximumHours = 25; user.MaximumCost = 1000; user.District = Districts.RURAL_NEW_SOUTH_WALES; users.Add(user); } foreach (var Users in users) { context.Users.Add(Users); } foreach (var InterventionType in interventionTypes) { context.InterventionTypes.Add(InterventionType); } base.Seed(context); }
/// <summary> /// This method use GetInterventionType method to get Intervention Type Data i.e Default Coast and Hours /// </summary> /// <param name="interventionTypeId">Id of an Intervention type</param> /// <returns>InterventionType</returns> public InterventionType GetInterventionTypeData(int interventionTypeId) { InterventionType interventionType = interventionDao.GetInterventionType(interventionTypeId); return(interventionType); }
/// <summary> /// Update an intervention type /// </summary> /// <param name="interventionType">Intervention type object</param> /// <returns>True if success, false if fail</returns> public bool update(InterventionType interventionType) { SqlCommand command = new SqlCommand(@"UPDATE InterventionTypes Set Name = @Name, Hours = @Hours, Costs = @Costs WHERE Id = @Id"); return(sqlExecuter.ExecuteNonQuery(command, interventionType) > 0); }