public void Charity_Operator_ConvertsGetCharityResponse() { var trustee = new CharityTrustee { TrusteeId = 123, Name = Guid.NewGuid().ToString() }; var response = new GetCharityResponse() { Id = 1234, RegistrationDate = DateTime.Now, RegistrationNumber = 1234, Name = Guid.NewGuid().ToString(), RegistrationStatus = "Registered", CharityType = "Other", RemovalDate = null, Trustees = new List <CharityTrustee> { trustee } }; Charity charity = response; Assert.AreEqual(1, charity.Trustees.Count); Assert.AreEqual(response.Id.ToString(), charity.CharityNumber); Assert.AreEqual(response.RegistrationNumber.ToString(), charity.RegistrationNumber); Assert.AreEqual(response.RegistrationDate, charity.RegistrationDate); Assert.AreEqual(response.Name, charity.Name); Assert.AreEqual(response.RegistrationStatus, charity.Status); Assert.AreEqual(response.CharityType, charity.Type); Assert.IsNull(charity.RemovalDate); }
//Aka save/update charity public void EditCharity(Charity charity) { var db = new ApplicationDbContext(); if (charity.CharityId == 0) { //first add any children //Add new user db.Charities.Add(charity); } else { Charity dbEntry = db.Charities.Find(charity.CharityId); if (dbEntry != null) { //dbEntry = charity; this works too, no change in the db data as far as I can tell dbEntry.Name = charity.Name; dbEntry.Address = charity.Address; dbEntry.City = charity.City; dbEntry.Zip = charity.Zip; dbEntry.Phone = charity.Phone; dbEntry.FederalTaxId = charity.FederalTaxId; dbEntry.TypeOfCharity = charity.TypeOfCharity; } } db.SaveChanges(); }
public IHttpActionResult PutCharity(int id, Charity charity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != charity.CharityID) { return(BadRequest()); } db.Entry(charity).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CharityExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task ThenTheMatchingOrganisationIsReturned() { var registrationNumber = 1234453; var expectedOrganisation = new Charity { Address1 = "Line1", Address2 = "Line 2", Address3 = "Line 3", Address4 = "Line 4", Address5 = "Line 5", Name = "Name", RegistrationNumber = 123435, PostCode = "AA11AA", RegistrationDate = DateTime.Now.AddYears(-3) }; Repository.Setup(x => x.GetCharityByRegistrationNumber(registrationNumber)).ReturnsAsync(expectedOrganisation); var result = await Service.Search(registrationNumber.ToString()); Assert.AreEqual(expectedOrganisation.Name, result.Name); Assert.AreEqual(expectedOrganisation.Address1, result.Address.Line1); Assert.AreEqual(expectedOrganisation.Address2, result.Address.Line2); Assert.AreEqual(expectedOrganisation.Address3, result.Address.Line3); Assert.AreEqual(expectedOrganisation.Address4, result.Address.Line4); Assert.AreEqual(expectedOrganisation.Address5, result.Address.Line5); Assert.AreEqual(expectedOrganisation.RegistrationNumber.ToString(), result.Code); Assert.AreEqual(expectedOrganisation.PostCode, result.Address.Postcode); Assert.AreEqual(expectedOrganisation.RegistrationDate, result.RegistrationDate); Assert.AreEqual(null, result.Sector); Assert.AreEqual(OrganisationSubType.None, result.SubType); Assert.AreEqual(OrganisationType.Charity, result.Type); }
public override ICharity GetCharityById(int id) { try { Charity charity = _store.Charities .Include(e => e.Category) .Include(e => e.CreatedBy) .Include(e => e.UpdatedBy) .Include(e => e.Locations) .Include(e => e.Volunteers) .Single(e => e.Id == id); charity.TotalHours = Math.Abs((_store.Hours .Where(x => x.CharityId == id) .Sum(x => DbFunctions.DiffMinutes(x.EndTime, x.StartTime)) ?? 0) / 60); charity.FollowersCount = charity.Volunteers.Count(); charity.AverageRating = _store.Hours .Where(x => x.CharityId == id) .Average(g => g.CharityRating ); return(CharityFactory.CreateCharity(charity)); } catch (InvalidOperationException) { return(null); } }
public void AddCharity(Charity charity) { var db = new ApplicationDbContext(); db.Charities.Add(charity); db.SaveChanges(); }
public IHttpActionResult PostCharity(Charity charity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Charities.Add(charity); try { db.SaveChanges(); } catch (DbUpdateException) { if (CharityExists(charity.CharityID)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = charity.CharityID }, charity)); }
public async Task DeleteCharityActionByKeyRequest_Handle_Returns_Null() { CharityActionContext.OpenInMemoryConnection(); try { //Arrange var busMock = new Mock <IBus>(); busMock.Setup(m => m.PublishAsync(It.IsAny <CharityActionDeletedEvent>())).Returns(Task.FromResult(true)); DeleteCharityActionResponse response; var keyAction = Guid.NewGuid(); var wrongKey = Guid.NewGuid(); var request = new DeleteCharityActionRequest { CharityActionKey = wrongKey, }; using (var context = CharityActionContext.GetInMemoryContext()) { var charity = new Charity { CharityKey = Guid.NewGuid() }; context.CharityActions.Add(new CharityAction { CharityActionKey = keyAction, UserKeys = new Collection <UserKey>() { new UserKey() { Key = Guid.NewGuid() } }, Category = Core.Enums.Category.AnimalProtection, IBAN = "", Name = "", Description = "0-IBAN", CoverImage = "", Charity = charity }); context.SaveChanges(); } //Act using (var context = CharityActionContext.GetInMemoryContext()) { var handler = new DeleteCharityActionRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile()), busMock.Object); response = await handler.Handle(request); } //Assert Assert.IsFalse(response.IsSuccess); } finally { CharityActionContext.CloseInMemoryConnection(); } }
public async Task <IActionResult> PutCharity(int id, Charity charity) { if (id != charity.CharityId) { return(BadRequest()); } _context.Entry(charity).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CharityExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public static CharityModel FromEntity(Charity charity) { var charityModel = new CharityModel(charity.Id); charityModel.MapFromEntity(charity); return(charityModel); }
public async Task Service_returns_charity_commission_details() { int charityNumber = 112233; _ukrlpDetails.Results[0].VerificationDetails = new List <VerificationDetails> { new VerificationDetails { PrimaryVerificationSource = true, VerificationAuthority = Domain.Ukrlp.VerificationAuthorities.CharityCommissionAuthority, VerificationId = charityNumber.ToString() } }; _roatpApiClient.Setup(x => x.GetUkrlpDetails(_ukprn)).ReturnsAsync(_ukrlpDetails); var charityDetails = new Charity { CharityNumber = charityNumber.ToString(), Name = "Test Name" }; _outerApiClient.Setup(x => x.GetCharityDetails(charityNumber)).ReturnsAsync(charityDetails); var result = await _service.GetExternalApiCheckDetails(_applicationId); result.CharityCommissionDetails.Should().NotBeNull(); result.CharityCommissionDetails.CharityNumber.Should().Be(charityDetails.CharityNumber); result.CharityCommissionDetails.Name.Should().Be(charityDetails.Name); }
public static bool AddCharity(Charity charity) { int ID = addCharity(charity.RegNumber, charity.UserRoleID, charity.UserFullName, charity.UserCity, charity.UserProvince, charity.UserPostalCode, charity.UserAddress1, charity.UserAddress2, charity.UserPhone, charity.UserWebsite, charity.UserEmail); if (ID == -1) { return(false); } if (!addCharityProfile(ID, charity.RegNumber, charity.CharityCategoryID, charity.CharityDesignationID)) { return(false); } foreach (string Program in charity.CharityPrograms) { bool valid = addCharityProgram(ID, Program); } foreach (string Country in charity.CharityCountries) { bool valid = addCharityActivityCountry(ID, Country); } return(true); }
/// <summary> /// Daniel Brown /// Created: /// 2017/04/03 /// /// Alters the status of a charity to denied /// </summary> /// /// <remarks> /// Aaron Usher /// Updated: /// 2017/04/04 /// /// Standardized method. /// </remarks> /// /// <param name="charity">The charity to deny.</param> /// <returns>Rows affected.</returns> public static int DenyCharity(Charity charity) { int rows = 0; var conn = DBConnection.GetConnection(); var cmdText = @"sp_update_charity_deny"; var cmd = new SqlCommand(cmdText, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@old_CHARITY_ID", charity.CharityID); try { conn.Open(); rows = cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } return(rows); }
public async Task <IActionResult> PutCharity([FromRoute] long id, [FromForm] Charity charity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != charity.Id) { return(BadRequest()); } _context.Entry(charity).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CharityExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public List <Runner> GetRunners() { var reader = Reader.GetTableReader(SponsorRequest.Runners()); var runners = new List <Runner>(); while (reader.Read()) { var charity = new Charity( reader["CharityId"].ToString(), reader["CharityName"].ToString(), reader["CharityDescription"].ToString(), reader["CharityLogo"].ToString() ); var runner = new Runner( reader["RunnerId"].ToString(), reader["RegistrationId"].ToString(), reader["FirstName"].ToString(), reader["LastName"].ToString(), reader["CountryName"].ToString(), reader["SponsorshipTarget"].ToString(), charity ); runners.Add(runner); } return(runners); }
public ActionResult CharityEdit(int charityId) { // Get the correct charity Charity charity = charRepo.GetCharities().FirstOrDefault(ch => ch.CharityId == charityId); return(View(charity)); }
public override void UpdateCharity(ICharity charityDTO) { Charity oldC = _store.Charities .Include(x => x.CreatedBy) .Include(x => x.UpdatedBy) .Include(x => x.Locations) .Single(x => x.Id == charityDTO.Id); _store.Entry(oldC).CurrentValues.SetValues(charityDTO); if (charityDTO.Category != null) { oldC.CategoryId = charityDTO.Category.Id; } if (charityDTO.CreatedBy != null) { oldC.CreatedById = charityDTO.CreatedBy.Id; } if (charityDTO.UpdatedBy != null) { oldC.UpdatedById = charityDTO.UpdatedBy.Id; } _store.SaveChanges(); }
public override int CreateCharity(ICharity charityDTO) { if (_store.Charities.Any(x => x.Name == charityDTO.Name)) { throw new ArgumentException(); //To-Do: Make custom exception for when duplicate names are found } Charity c = CharityFactory.CreateCharity(charityDTO); if (charityDTO.Category != null) { c.CategoryId = charityDTO.Category.Id; } if (charityDTO.CreatedBy != null) { c.CreatedById = charityDTO.CreatedBy.Id; } if (charityDTO.UpdatedBy != null) { c.UpdatedById = charityDTO.UpdatedBy.Id; } c = _store.Charities.Add(c); _store.SaveChanges(); return(c.Id); }
public void AddCharity(Charity charity) { var db = new CapstoneDbContext(); db.Charities.Add(charity); db.SaveChanges(); }
public void Save(Charity charity) { if (charity.Id == 0) _dataContext.Charities.Add(charity); _dataContext.SaveChanges(); }
//Aka save/update charity public void EditCharity(Charity charity) { var db = new CapstoneDbContext(); if (charity.CharityId == 0) { //first add any children //Add new user db.Charities.Add(charity); } else { Charity dbEntry = db.Charities.Find(charity.CharityId); if (dbEntry != null) { dbEntry.Name = charity.Name; dbEntry.Address = charity.Address; dbEntry.City = charity.City; dbEntry.Zip = charity.Zip; dbEntry.Phone = charity.Phone; dbEntry.FederalTaxId = charity.FederalTaxId; dbEntry.TypeOfCharity = charity.TypeOfCharity; } } db.SaveChanges(); }
private async Task <Charity> GetOrAddCharity(DonorContext db, bool commitTransaction = true) { if (!CharityIdentifier.HasValue) { throw new Exception($"'{nameof(CharityIdentifier)}' is empty."); } var charity = await GetCharity(db); if (charity != null) { return(charity); } charity = new Charity { Identifier = CharityIdentifier.Value, CharityName = CharityName }; db.Charities.Add(charity); if (commitTransaction) { await db.SaveChangesAsync(); } return(charity); }
private static bool ReloadCharityData(Charity _Charity, ApplicationDbContext db) { if (_Charity == null) { throw new ArgumentNullException(nameof(_Charity)); } if (db == null) { throw new ArgumentNullException(nameof(db)); } var reloadedData = GetCharityDetailsByJustGivingID(_Charity.JustGivingCharityID); var relatedDataJSON = Json.Decode(reloadedData); _Charity.JustGivingCharityBlob = reloadedData; _Charity.JustGivingCharityImageURL = relatedDataJSON.logoAbsoluteUrl; _Charity.JustGivingRegistrationNumber = relatedDataJSON.registrationNumber; _Charity.Name = relatedDataJSON.name; _Charity.CharityURL = relatedDataJSON.websiteUrl; _Charity.Description = relatedDataJSON.description; db.SaveChanges(); return(true); }
internal int saveCharity(Charity charity) { using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand("sp_AdminCreateCharity", sqlConnection)) { try { sqlConnection.Open(); command.CommandType = CommandType.StoredProcedure; if (charity.Id == null) { command.Parameters.AddWithValue("@Id", DBNull.Value); } else { command.Parameters.AddWithValue("@Id", charity.Id); } command.Parameters.AddWithValue("@Help_EN", charity.Help_EN); command.Parameters.AddWithValue("@Help_AM", charity.Help_AM); command.Parameters.AddWithValue("@Money", charity.Money); command.Parameters.AddWithValue("@OccureDate", charity.OccureDate); return(Convert.ToInt32(command.ExecuteScalar())); } catch (Exception ex) { throw ex; } } } }
private Attachment GetCharityHeroCard(Charity charity) { List <CardImage> cardImages = new List <CardImage>(); cardImages.Add(new CardImage(charity.ImageUrl)); List <CardAction> cardButtons = new List <CardAction>(); CardAction donateButton = new CardAction() { Value = $"donate|{charity.EventCode}", Type = "postBack", // note: cortana does not support 'imback' Title = "donate" }; CardAction learnMoreButton = new CardAction() { Value = charity.Website, Type = "openUrl", Title = "learn more" }; cardButtons.Add(donateButton); cardButtons.Add(learnMoreButton); HeroCard plCard = new HeroCard() { Title = charity.Name, Subtitle = string.Join(" ", charity.Causes), Images = cardImages, Buttons = cardButtons }; return(plCard.ToAttachment()); }
public async Task <IActionResult> Edit(int id, [Bind("CharityId,CharityDetails,CharityName,CharityOrganization,CharityLocation,CharityLink,CtypeName")] Charity charity) { if (id != charity.CharityId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(charity); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CharityExists(charity.CharityId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CtypeName"] = new SelectList(_context.CharityType, "CtypeName", "CtypeName", charity.CtypeName); return(View(charity)); }
public async Task <ActionResult <Charity> > PostCharity(Charity charity) { _context.Charity.Add(charity); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCharity", new { id = charity.CharityId }, charity)); }
public void TestPasswordEncryption() { const string password = "******"; var target = new Charity(); target.SetPassword(password); Assert.IsTrue(target.VerifyPassword(password)); }
public void RefreshTrustees_UpdateTrusteesReturnsFalse_ExceptionThrown() { const int ukprn = 12345678; const string charityNumber = "87654321"; var organisation = new Organisation { OrganisationUkprn = ukprn }; if (int.TryParse(charityNumber, out var charityNumberValue)) { organisation.OrganisationDetails = new OrganisationDetails { CharityNumber = charityNumber, CharityCommissionDetails = new CharityCommissionDetails() }; } _organisationApiClient.Setup(x => x.GetByApplicationId(_applicationId)).ReturnsAsync(organisation); var listOfTrustees = new List <Trustee> { new Trustee { Id = 1234, Name = "Mr A Trustee" }, new Trustee { Id = 1235, Name = "Mr B Trustee" } }; var charity = new Charity { CharityNumber = charityNumber, Trustees = listOfTrustees, Status = "registered" }; _qnaApiClient.Setup(x => x.GetQuestionTag(_applicationId, RoatpWorkflowQuestionTags.UKPRN)).ReturnsAsync(ukprn.ToString()); _qnaApiClient.Setup(x => x.GetQuestionTag(_applicationId, RoatpWorkflowQuestionTags.UKRLPVerificationCharityRegNumber)).ReturnsAsync(charityNumber); _organisationApiClient.Setup(x => x.UpdateTrustees(ukprn.ToString(), listOfTrustees, It.IsAny <Guid>())).ReturnsAsync(false); _applicationApiClient.Setup(x => x.GetApplication(_applicationId)).ReturnsAsync(new Apply { ApplicationStatus = ApplicationStatus.InProgress }); _outerApiClient.Setup(x => x.GetCharityDetails(charityNumberValue)).ReturnsAsync(charity).Verifiable(); var updateResponse = new SetPageAnswersResponse { ValidationPassed = true }; _qnaApiClient.Setup(x => x.UpdatePageAnswers(_applicationId, RoatpWorkflowSequenceIds.YourOrganisation, RoatpWorkflowSectionIds.YourOrganisation.WhosInControl, It.IsAny <string>(), It.IsAny <List <Answer> >())).ReturnsAsync(updateResponse); Assert.ThrowsAsync <InvalidOperationException>(() => _service.RefreshTrustees(_applicationId, _userId)); }
public async Task GetCharityByKeyRequest_Handle_Returns_Charity() { CharityContext.OpenInMemoryConnection(); try { //Arrange var key = Guid.NewGuid(); using (var context = CharityContext.GetInMemoryContext()) { var charity = new Charity { CharityKey = key, Name = "testNameCharity", OwnerUserName = "******", Email = "*****@*****.**", Category = Core.Enums.Category.None, KVKNumber = "", IBAN = "0-IBAN", CoverImage = "", Slogan = "Test" }; context.Add(charity); context.SaveChanges(); } var request = new GetCharityByKeyRequest() { CharityKey = key }; GetCharityByKeyResponse response; //Act using (var context = CharityContext.GetInMemoryContext()) { var handler = new GetCharityByKeyRequestHandler(context, AutoMapperHelper.BuildMapper(new MappingProfile())); response = await handler.Handle(request); } //Assert using (var context = CharityContext.GetInMemoryContext()) { Assert.AreEqual(response.Charity.CharityKey, request.CharityKey); Assert.AreEqual(response.Charity.Name, context.Charities.Single().Name); Assert.AreEqual(response.Charity.OwnerUserName, context.Charities.Single().OwnerUserName); Assert.AreEqual(response.Charity.Email, context.Charities.Single().Email); Assert.AreEqual(response.Charity.Category, context.Charities.Single().Category); Assert.AreEqual(response.Charity.KVKNumber, context.Charities.Single().KVKNumber); Assert.AreEqual(response.Charity.IBAN, context.Charities.Single().IBAN); Assert.AreEqual(response.Charity.CoverImage, context.Charities.Single().CoverImage); Assert.AreEqual(response.Charity.Slogan, context.Charities.Single().Slogan); Assert.IsTrue(response.IsSuccess); } } finally { CharityContext.CloseInMemoryConnection(); } }
public ViewResult EditCharity(int id) { ViewBag.FormTitle = "Edit Charity"; Charity c = _charCatRepo.Charities.Where(x => x.ID == id).FirstOrDefault(); return(View(c)); }
private Charity ApproveCharity(int id, bool approve) { Charity charity = _charityRepository.Get(id); charity.Approved = approve; _charityRepository.Save(charity); return(charity); }
public ActionResult AddCharity(Charity charity) { if (ModelState.IsValid) { _charityRepository.Save(charity); RedirectToAction("Charities"); } return View(charity); }
public ActionResult Register(FormCollection f) { string icap = f["inputCaptcha"]; if (icap == "") { Account acc = new Account(); acc.Email = f["email"]; acc.Password = f["password"]; acc.RoleID = int.Parse(f["role"]); Profile pro = new Profile(); pro.Firstname = f["firstname"]; pro.Lastname = f["lastname"]; pro.Gender = bool.Parse(f["gender"]); pro.DateOfBirth = DateTime.Parse(f["dateOfBirth"]); pro.PhoneNumber = f["phoneNumber"]; pro.Address = f["address"]; pro.DistrictID = int.Parse(f["district"]); TempData["acc"] = acc; TempData["pro"] = pro; TempData["emptyCaptcha"] = "Captcha rỗng"; return RedirectToAction("Register", "Account"); } else if (icap != "") { if (icap != Session["Captcha"].ToString()) { TempData["wrongCaptcha"] = "Kết quả sai"; return Redirect("Register"); } else if (icap == Session["Captcha"].ToString()) { Account acc = new Account(); acc.Email = f["email"]; acc.Password = f["password"]; acc.IsActive = false; acc.RoleID = int.Parse(f["role"]); db.Accounts.Add(acc); db.SaveChanges(); switch (acc.RoleID) { case 1: Candidate can = new Candidate(); can.AccountID = acc.AccountID; db.Candidates.Add(can); break; case 2: Charity cha = new Charity(); cha.AccountID = acc.AccountID; db.Charities.Add(cha); break; case 3: Sponsor sp = new Sponsor(); sp.AccountID = acc.AccountID; db.Sponsors.Add(sp); break; case 4: Volunteer vo = new Volunteer(); vo.AccountID = acc.AccountID; //vo.JobName = f["job"]; //vo.Description = f["des"]; db.Volunteers.Add(vo); break; } db.SaveChanges(); Profile pro = new Profile(); pro.AccountID = acc.AccountID; pro.Firstname = f["firstname"]; pro.Lastname = f["lastname"]; pro.Gender = bool.Parse(f["gender"]); pro.DateOfBirth = DateTime.Parse(f["dateOfBirth"]); pro.PhoneNumber = f["phoneNumber"]; pro.Address = f["address"]; pro.DistrictID = int.Parse(f["district"]); db.Profiles.Add(pro); db.SaveChanges(); acc.ProfileID = pro.ProfileID; db.SaveChanges(); Session.Clear(); //string strRandomCode = RandomCode(6); //string abc = null; //MailMessage loginInfo = new MailMessage(); //loginInfo.To.Add(acc.Email); //loginInfo.From = new MailAddress("TSMT<*****@*****.**>"); //loginInfo.Subject = "Confirm Your Registration"; //loginInfo.Body = "Hello. Mr/Mrs/Miss <b>" + acc.Profile.Lastname + " " + acc.Profile.Firstname + "</b> Welcome to TSMT. Thanks for your registration! Your confirmation code: <b>" + strRandomCode + "</b><br/><br/>Please click <a href=" + abc + ">here </a>to confirm registration"; ////loginInfo.Body = "Tên khách hàng: " + TBten.Text + "<br><br>Nhấp <a href=" + sss + ">vào đây</a> để xác nhận tài khoản "; //loginInfo.IsBodyHtml = true; //SmtpClient smtp = new SmtpClient(); //smtp.Host = "smtp.gmail.com"; //smtp.Port = 587; //smtp.EnableSsl = true; //smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "64689205"); //smtp.Send(loginInfo); } } return RedirectToAction("Index", "Home"); }
public void Delete(Charity charity) { _dataContext.Charities.Remove(charity); _dataContext.SaveChanges(); }