private ServiceTypeModel getServiceTypeModel(int id) { ServiceTypeModel stm = new ServiceTypeModel(); try { queryString = "SELECT ID, serviceType AS 'SERVICE TYPE', price AS 'PRICE' FROM dbspa.tblservicetype WHERE (isDeleted = 0) AND (ID = ?)"; parameters = new List <string>(); parameters.Add(id.ToString()); MySqlDataReader reader = conDB.getSelectConnection(queryString, parameters); while (reader.Read()) { stm.ServiceType = reader["SERVICE TYPE"].ToString(); stm.Price = reader["price"].ToString(); stm.ID1 = reader["ID"].ToString(); } conDB.closeConnection(); } catch (Exception ex) { MessageBox.Show(ex.Message); } return(stm); }
public void ValidateForDuplicate(ServiceTypeModel viewModel) { if (ServiceTypeRepository.Items.Any(p => p.Name == viewModel.Name && p.Id != viewModel.Id && p.IsActive)) { throw new ValidationException(new ValidationResult("Name already exists.", new string[] { "Name" }), null, viewModel); } }
private List <ServiceTypeModel> getServiceWithCommissions() { List <ServiceTypeModel> lstServiceModel = new List <ServiceTypeModel>(); try { queryString = "SELECT dbspa.tblservicetype.ID, dbspa.tblservicetype.serviceType AS 'SERVICE TYPE', dbspa.tblservicetype.price FROM " + "(dbspa.tblservicetype INNER JOIN dbspa.tblcommissions ON dbspa.tblservicetype.ID = dbspa.tblcommissions.serviceTypeID) WHERE " + "(dbspa.tblservicetype.isDeleted = 0) AND (dbspa.tblcommissions.isDeleted = 0)"; MySqlDataReader reader = conDB.getSelectConnection(queryString, null); while (reader.Read()) { ServiceTypeModel stm = new ServiceTypeModel(); stm.ServiceType = reader["SERVICE TYPE"].ToString(); stm.Price = reader["price"].ToString(); stm.ID1 = reader["ID"].ToString(); lstServiceModel.Add(stm); } conDB.closeConnection(); } catch (Exception ex) { MessageBox.Show(ex.Message); } return(lstServiceModel); }
private void insertServiceTypeWithCommission() { try { queryString = "INSERT INTO dbspa.tblcommissions (serviceTypeID,commission,isDeleted)VALUES(?, ?, ?)"; parameters = new List <string>(); ServiceTypeModel stm = cmbServiceType.SelectedItem as ServiceTypeModel; parameters.Add(stm.ID1); parameters.Add(String.Format("{0:0.00}", txtCommission.Text)); parameters.Add(0.ToString()); conDB.AddRecordToDatabase(queryString, parameters); conDB.closeConnection(); MessageBox.Show("RECORD SAVED SUCCESSFULLY!"); conDB.writeLogFile("ADDED COMMISSION RECORD: SERVICE TYPE ID: " + stm.ID1 + " COMMISSION: " + String.Format("{0:0.00}", txtCommission.Text)); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { getDatagridDetails(); } }
public void GivenUserIsNotDataAdmin_WhenGenerateCreateViewModel_ThenViewModelIsAdministratorFalse() { ServiceTypeModel actual = Target.GenerateCreateViewModel(User); Assert.IsNotNull(actual); Assert.IsFalse(actual.IsAdministrator); }
private void btnAdd_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(txtCommission.Text)) { MessageBox.Show("Please input commission value"); } else if (cmbServiceType.SelectedItem == null) { MessageBox.Show("Please select Service Type value"); } else { ServiceTypeModel s = cmbServiceType.SelectedItem as ServiceTypeModel; if (s != null) { if (s.ifPromo) { updatePromoNameWithCommission(s.ID1); } else { insertServiceTypeWithCommission(); } } } }
public void WhenGenerateCreateViewModel_ThenAPartialViewResultIsReturned() { ServiceTypeModel actual = Target.GenerateCreateViewModel(User); Assert.IsNotNull(actual); Assert.IsFalse(actual.IsAdministrator); }
public void WhenGenerateCreateViewModel_ThenAPartialViewResultWithAPopulatedCategoryListIsReturned() { ServiceTypeModel actual = Target.GenerateCreateViewModel(User); Assert.IsNotNull(actual.Categories); CollectionAssert.AreEqual(Data.Categories, actual.Categories.Items.Cast <Category>().ToList()); }
public void WhenGenerateCreateViewModel_ThenAPartialViewResultWithAPopulatedProgramListIsReturned() { ServiceTypeModel actual = Target.GenerateCreateViewModel(User); Assert.IsNotNull(actual.Programs); CollectionAssert.AreEqual(Data.Programs.Where(p => p.IsActive).ToList(), actual.Programs.Items.Cast <Program>().ToList()); }
public void WhenGenerateCreateViewModel_ThenViewModelProgramListColumnsAreCorrect() { ServiceTypeModel actual = Target.GenerateCreateViewModel(User); Assert.AreEqual("Id", actual.Programs.DataValueField); Assert.AreEqual("Name", actual.Programs.DataTextField); }
/// <summary> /// Insert a new value in the list /// </summary> /// <param name=<em>"value"</em>>New value to be inserted</param> // POST: api/ServiceType public IHttpActionResult Post(ServiceTypeModel country) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } using (var ctx = new HTMEntities3()) { ctx.ServiceTypes.Add(new ServiceType() { id = country.id, ServiceTypeName = country.ServiceTypeName, Description = country.Description, InsertedBy = country.InsertedBy, InsertedOn = country.InsertedOn, IsActive = country.IsActive, IsDelete = country.IsDelete }); ctx.SaveChanges(); } return(Ok()); }
private List <ServiceTypeModel> getServiceType(List <ServiceMadeModel> smm) { List <ServiceTypeModel> lstSTM = new List <ServiceTypeModel>(); ServiceTypeModel tm = new ServiceTypeModel(); foreach (ServiceMadeModel madeModel in smm) { queryString = "SELECT ID, serviceType, price FROM dbspa.tblservicetype WHERE ID = ? AND isDeleted=0"; parameters = new List <string>(); parameters.Add(madeModel.ServiceType); MySqlDataReader reader = conDB.getSelectConnection(queryString, parameters); while (reader.Read()) { tm.ID1 = reader["ID"].ToString(); tm.ServiceType = reader["serviceType"].ToString(); tm.Price = reader["price"].ToString(); lstSTM.Add(tm); tm = new ServiceTypeModel(); } conDB.closeConnection(); } return(lstSTM); }
public void fillListBoxServiceType(ComboBox combo, ServiceTypeModel servType) { try { queryString = "SELECT dbspa.tblservicetype.ID, dbspa.tblservicetype.serviceType AS 'SERVICE TYPE', dbspa.tblservicetype.price AS 'PRICE', " + "description FROM dbspa.tblservicetype WHERE (isDeleted = 0)"; MySqlDataReader reader = conDB.getSelectConnection(queryString, null); while (reader.Read()) { ServiceTypeModel stm = new ServiceTypeModel(); stm.ServiceType = reader["SERVICE TYPE"].ToString(); stm.Price = reader["price"].ToString(); stm.ID1 = reader["ID"].ToString(); stm.Description = reader["description"].ToString(); combo.Items.Add(stm); if (stm.ID1.Equals(servType.ID1)) { combo.SelectedItem = stm; } } conDB.closeConnection(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnAdd_Click(object sender, RoutedEventArgs e) { if (cmbPromos.Visibility != Visibility.Hidden) { if (verifySelection()) { PromoModel promo = cmbPromos.SelectedItem as PromoModel; addServiceToPromo(promo.ID); //label.Content = "Promo Name: " + promo.PromoName; loadDataGridServices(promo.ID); } } else { ServiceTypeModel selectService = cmbServices.SelectedItem as ServiceTypeModel; if (selectService != null) { addServiceToPromo(insertedPromoID); loadDataGridServices(insertedPromoID); } else { MessageBox.Show("Please select Service!"); } } }
public void GivenViewModel_WhenCreate_ThenServiceTypeIsActive() { ServiceTypeModel viewModel = new ServiceTypeModel(); Target.Create(viewModel); Repositories.MockServiceTypeRepository.AssertWasCalled(m => m.Add(Arg <ServiceType> .Matches(s => s.IsActive == true))); }
public void GivenNewServiceTypeState_WhenCreatePosted_ThenLogicManagerCreatesServiceType() { ServiceTypeModel expected = new ServiceTypeModel(); Target.Create(expected); MockLogicManager.AssertWasCalled(m => m.Create(expected)); }
public void GivenANewlyCreatedIsSubmitted_WhenCreatePosted_ThenTrueJsonResultReturned() { ServiceTypeModel viewModel = new ServiceTypeModel(); JsonResult result = Target.Create(viewModel) as JsonResult; Assert.AreEqual(true, result.Data); }
public void GivenValidViewModel_WhenCreate_ThenSaveCalled() { ServiceTypeModel viewModel = new ServiceTypeModel(); Target.Create(viewModel); Repositories.MockRepositoryContainer.AssertWasCalled(m => m.Save()); }
public void GivenViewModelHasDuplicateName_AndServiceTypeWithNameIsInactive_WhenValidateForDuplicate_ThenSucceed() { var model = new ServiceTypeModel { Name = Data.ServiceTypes[5].Name }; Target.ValidateForDuplicate(model); }
public void GivenViewModelHasNewName_WhenValidateForDuplicate_ThenSucceed() { var model = new ServiceTypeModel { Name = "Mentoring 2" }; Target.ValidateForDuplicate(model); }
public void GivenInvalidServiceTypeId_WhenEdit_ThenThrowException() { ServiceTypeModel viewModel = new ServiceTypeModel { Id = 100 }; Target.ExpectException <EntityNotFoundException>(() => Target.Edit(viewModel)); }
public void GivenServiceTypeServiceOfferingsToBeDeactivatedHaveStudentAssignedOfferings_WhenEdit_ThenThrowException() { var selectedPrograms = new int[] { 3, 4 }; var viewModel = new ServiceTypeModel { Id = 1, SelectedPrograms = selectedPrograms }; Target.ExpectException <ValidationException>(() => Target.Edit(viewModel)); }
public void GivenAnInvalidModelState_WhenIEditType_ThenTheCorrectCategoriesAreAddedToTheViewModel() { var expected = new ServiceTypeModel { Id = 1, Name = "Mentoring" }; MockLogicManager.Expect(m => m.ValidateForDuplicate(expected)).Throw(new ValidationException(new ValidationResult("Error!", new[] { "Name" }), null, expected)); Target.Edit(expected); MockLogicManager.AssertWasCalled(m => m.PopulateViewModel(User, expected)); }
public void GivenLogicManagerGeneratesViewModel_WhenCreateActionIsCalled_ThenReturnedPartialViewContainsViewModel() { ServiceTypeModel expected = new ServiceTypeModel(); MockLogicManager.Expect(m => m.GenerateCreateViewModel(User)).Return(expected); PartialViewResult result = Target.Create(); result.AssertGetViewModel(expected); }
public void GivenViewModelHasInvalidState_WhenCreatePosted_ThenViewResultContainsValidationErrorMessage() { Target.ModelState.AddModelError("Name", new ValidationException()); var model = new ServiceTypeModel(); PartialViewResult result = Target.Create(model) as PartialViewResult; result.AssertGetViewModel(model); }
public void GivenViewModel_WhenPopulateViewModel_ThenCategoriesAndProgramsListsSet() { ServiceTypeModel model = new ServiceTypeModel(); Target.PopulateViewModel(User, model); Assert.IsNotNull(model.Categories); Assert.IsNotNull(model.Programs); }
public void GivenViewModelIsGenerated_WhenEditButtonIsClicked_ThenAViewResultIsCreated() { ServiceTypeModel expected = new ServiceTypeModel(); MockLogicManager.Expect(m => m.GenerateEditViewModel(User, 1)).Return(expected); var result = Target.Edit(1) as PartialViewResult; result.AssertGetViewModel(expected); }
public void GivenValidServiceTypeId_WhenICallDelete_ThenAPartialViewResultIsReturned() { ServiceTypeModel expected = new ServiceTypeModel(); MockLogicManager.Expect(m => m.GenerateDeleteViewModel(1)).Return(expected); var result = Target.Delete(1) as PartialViewResult; result.AssertGetViewModel(expected); }
public void GivenViewModelHasDuplicateName_WhenValidateForDuplicate_ThenThrowValidationException_AndExceptionMemberNamesIncludesName() { var model = new ServiceTypeModel { Name = "Mentoring" }; ValidationException actual = Target.ExpectException <ValidationException>(() => Target.ValidateForDuplicate(model)); CollectionAssert.Contains(actual.ValidationResult.MemberNames.ToList(), "Name"); }
public void GivenAnEditedServiceTypeIsSubmittedWithoutAUniqueName_WhenEditPosted_ThenReturnViewResultWithViewModel_AndNameHasModelStateErrors() { var expected = new ServiceTypeModel { Id = 1, Name = "Mentoring" }; MockLogicManager.Expect(m => m.ValidateForDuplicate(expected)).Throw(new ValidationException(new ValidationResult("Error!", new[] { "Name" }), null, expected)); PartialViewResult result = Target.Edit(expected) as PartialViewResult; result.AssertGetViewModel(expected); Assert.IsTrue(Target.ModelState["Name"].Errors.Count > 0); }
public List <ServiceTypeModel> ServiceTypeList() { var modelView = new ServiceTypeModel { FilterOption = FilterOption.GetAll }; var viewJson = Execute(Option.Get, modelView); var responseModel = GetResponseModel <ServiceTypeModel>(viewJson); return(responseModel.ModelList); }
public ServiceTypeModel GetServiceTypeById(int id) { var modelView = new ServiceTypeModel { Id = id, FilterOption = FilterOption.ModelByFields }; var viewJson = Execute(Option.Get, modelView); var responseModel = GetResponseModel <ServiceTypeModel>(viewJson); return(responseModel.Model); }
public void GivenServiceTypeAssociationsWereMade_WhenEdit_ThenServiceTypeHasSelectedPrograms() { EducationSecurityPrincipal user = new EducationSecurityPrincipal(new UserRepository(EducationContext).Items.Where(s => s.UserKey == "Bob").Include("UserRoles.Role").Single()); var selectedPrograms = new int[] { 1, 2 }; var serviceType = EducationContext.ServiceTypes.Single(s => s.Id == 2); var expected = EducationContext.Programs.Where(s => selectedPrograms.Contains(s.Id)).ToList(); var viewModel = new ServiceTypeModel { Id = serviceType.Id, Name = serviceType.Name, Description = serviceType.Description, SelectedPrograms = selectedPrograms }; Target.Edit(viewModel); var actual = EducationContext.ServiceTypes.Single(s => s.Id == viewModel.Id).ServiceOfferings.Where(s => s.IsActive).Select(s => s.Program).Distinct(); CollectionAssert.AreEquivalent(expected, actual.ToList()); }
public ActionResult Create(ServiceTypeModel viewModel) { try { LogicManager.ValidateForDuplicate(viewModel); } catch (ValidationException e) { ModelState.AddModelErrors(e); } if (ModelState.IsValid) { LogicManager.Create(viewModel); return Json(true); } LogicManager.PopulateViewModel((EducationSecurityPrincipal)HttpContext.User, viewModel); return PartialView(viewModel); }
public void Create(ServiceTypeModel viewModel) { if (viewModel == null) { throw new ArgumentNullException("viewModel"); } ServiceType item = new ServiceType { IsActive = true }; viewModel.CopyTo(item); if (ServiceTypeRepository.Items.Any(s => s.Name == item.Name && !s.IsActive)) { item = ServiceTypeRepository.Items.Include("ServiceOfferings.Program.Schools").Single(s => s.Name == item.Name); item.IsActive = true; } else { ServiceTypeRepository.Add(item); } UpdateTypeCategories(viewModel.SelectedCategories, item); UpdateServiceTypePrograms(viewModel.SelectedPrograms, item); RepositoryContainer.Save(); }
public void WhenACreateActionIsPosted_ThenAActionResultIsReturned() { ServiceTypeModel model = new ServiceTypeModel { Id = 0, Name = "Bob", Description = "Bob's Description" }; ActionResult result = Target.Create(model); Assert.IsNotNull(result); }
public void InitializeTest() { Target = new ServiceTypeModel(); }
public ServiceTypeModel GenerateCreateViewModel(EducationSecurityPrincipal user) { if (user == null) { throw new ArgumentNullException("user"); } ServiceTypeModel model = new ServiceTypeModel(); PopulateViewModel(user, model); return model; }
public void GivenValidationExceptionThrown_WhenDeleteIsClicked_ThenAPartialViewResultIsCreated_AndExpectedViewModelGenerated() { ServiceTypeModel expected = new ServiceTypeModel(); MockLogicManager.Expect(m => m.Delete(1)).Throw(new ValidationException()); MockLogicManager.Expect(m => m.GenerateDeleteViewModel(1)).Return(expected); PartialViewResult result = Target.DeleteConfirmed(1) as PartialViewResult; result.AssertGetViewModel(expected); }
public void PopulateViewModel(EducationSecurityPrincipal user, ServiceTypeModel viewModel) { if (viewModel == null) { throw new ArgumentNullException("viewModel"); } viewModel.IsAdministrator = user.IsInRole(SecurityRoles.DataAdmin); viewModel.Categories = new MultiSelectList(CategoryRepository.Items, "Id", "Name", viewModel.SelectedCategories); viewModel.Programs = new MultiSelectList(ProgramRepository.Items.Where(p => p.IsActive), "Id", "Name", viewModel.SelectedPrograms); }
public ServiceTypeModel GenerateEditViewModel(EducationSecurityPrincipal user, int typeId) { if (user == null) { throw new ArgumentNullException("user"); } var serviceType = ServiceTypeRepository.Items.Include(s => s.Categories).Include("ServiceOfferings.Program").SingleOrDefault(s => s.Id == typeId && s.IsActive); if (serviceType == null) { throw new EntityNotFoundException("Specified service type does not exist"); } ServiceTypeModel viewModel = new ServiceTypeModel(); viewModel.CopyFrom(serviceType); viewModel.Categories = new MultiSelectList(CategoryRepository.Items, "Id", "Name", serviceType.Categories.Select(c => c.Id)); viewModel.Programs = new MultiSelectList(ProgramRepository.Items.Where(p => p.IsActive), "Id", "Name", serviceType.ServiceOfferings.Where(so => so.IsActive && so.Program.IsActive).Select(s => s.ProgramId).Distinct()); viewModel.IsAdministrator = user.IsInRole(SecurityRoles.DataAdmin); return viewModel; }
public void GivenViewModelHasDuplicateName_WhenCreatePosted_ThenModelStateHasErrors() { var model = new ServiceTypeModel { Name = "Mentoring" }; MockLogicManager.Expect(m => m.ValidateForDuplicate(model)).Throw(new ValidationException(new ValidationResult("Error!", new[] { "Name" }), null, model)); PartialViewResult result = Target.Create(model) as PartialViewResult; Assert.IsTrue(Target.ModelState["Name"].Errors.Count > 0); }
public ServiceTypeModel GenerateDeleteViewModel(int typeId) { var model = ServiceTypeRepository.Items.SingleOrDefault(s => s.Id == typeId); if (model == null) { throw new EntityNotFoundException("Specified service type does not exist"); } ServiceTypeModel viewModel = new ServiceTypeModel(); viewModel.CopyFrom(model); return viewModel; }
public void GivenViewModelHasInvalidState_WhenCreatePosted_ThenViewResultWithViewModelReturned_AndViewModelPopulatedLists() { var expected = new ServiceTypeModel(); Target.ModelState.AddModelError("Name", new ValidationException()); PartialViewResult result = Target.Create(expected) as PartialViewResult; MockLogicManager.AssertWasCalled(m => m.PopulateViewModel(User, expected)); result.AssertGetViewModel(expected); }
public void Edit(ServiceTypeModel viewModel) { var updatedServiceType = ServiceTypeRepository.Items.Include("ServiceOfferings.Program.Schools").Include(s => s.Categories).Include("ServiceOfferings.Program").SingleOrDefault(s => s.Id == viewModel.Id); if (updatedServiceType == null) { throw new EntityNotFoundException("Service Type not found."); } viewModel.CopyTo(updatedServiceType); ServiceTypeRepository.Update(updatedServiceType); UpdateTypeCategories(viewModel.SelectedCategories, updatedServiceType); UpdateServiceTypePrograms(viewModel.SelectedPrograms, updatedServiceType); RepositoryContainer.Save(); }