// GET: Donation/Edit/5 //UPDATED CODE to get the event id to edit although I dont think event id needs to be edited as anything with money should not be edit not sure how to lock that down public ActionResult Edit(int id) { //add n the new view model and create a new instance of it UpdateDonation ViewModel = new UpdateDonation(); //starting with the url string REFERENCES:varsity MVP for this code and inclass live example //this is where I had issues in my passion project!!!! (Mind blown) string url = "DonationData/FindDonation/" + id; //reusing code from "Find Donation By Id". HttpResponseMessage response = client.GetAsync(url).Result; // The http call worked. if (response.IsSuccessStatusCode) { DonationDto Selecteddonation = response.Content.ReadAsAsync <DonationDto>().Result; ViewModel.donation = Selecteddonation; //adding in event id //REUSING CODE FROM create donation //url : from AMANDA's DATA CONTROLLER url = "EventData/GetEvents"; response = client.GetAsync(url).Result; IEnumerable <EventDto> PotentialEvents = response.Content.ReadAsAsync <IEnumerable <EventDto> >().Result; ViewModel.allevents = PotentialEvents; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult FindDonationForDonor(string id) { //SELECET * FROM User, Donation WHERE U.UserID = D.UserID AND DonationId = id Donation Donation = db.Donations .Where(d => d.Id == id) .FirstOrDefault(); if (Donation == null) { return(NotFound()); } //Information to be return DonationDto DonationDto = new DonationDto { DonationId = Donation.DonationId, AmountOfDonation = Donation.AmountOfDonation, PaymentMethod = Donation.PaymentMethod, DonationDate = Donation.DonationDate, Id = Donation.Id, DepartmentId = Donation.DepartmentId }; return(Ok(DonationDto)); }
public IHttpActionResult FindDonation(int id) { Donation Donation = db.donations.Find(id); //not found 404 status code. if (Donation == null) { return(NotFound()); } DonationDto DonationDto = new DonationDto { donationId = Donation.donationId, firstName = Donation.firstName, lastName = Donation.lastName, email = Donation.email, phoneNumber = Donation.phoneNumber, amount = Donation.amount, //add event id EventId = Donation.EventId, }; //if donation is in the database 200 status code OK response return(Ok(DonationDto)); }
public IHttpActionResult GetDonations() { //FOR MY UNDERSTANDING: go to donations dto and get the list List <Donation> Donations = db.donations.ToList(); //FOR MY UNDERSTANDING: show the list in the donation database List <DonationDto> DonationDtos = new List <DonationDto> { }; //information to be displayed foreach (var Donation in Donations) { Event Event = db.events .Where(e => e.Donations.Any(d => d.EventId == Donation.EventId)) .FirstOrDefault(); DonationDto NewDonation = new DonationDto { donationId = Donation.donationId, firstName = Donation.firstName, lastName = Donation.lastName, email = Donation.email, phoneNumber = Donation.phoneNumber, amount = Donation.amount, //add event id EventId = Donation.EventId, }; DonationDtos.Add(NewDonation); } //if status code 200 list donations return(Ok(DonationDtos)); }
// GET: Donation/Details/5 public ActionResult Details(int id) { ShowDonation ViewModel = new ShowDonation(); string url = "donationdata/finddonation/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Can catch the status code (200 OK, 301 REDIRECT), etc. //Debug.WriteLine(response.StatusCode); if (response.IsSuccessStatusCode) { //Put data into donation data transfer object DonationDto SelectedDonation = response.Content.ReadAsAsync <DonationDto>().Result; ViewModel.donation = SelectedDonation; url = "donationdata/finddonorfordonation/" + id; response = client.GetAsync(url).Result; DonorDto SelectedDonor = response.Content.ReadAsAsync <DonorDto>().Result; ViewModel.donor = SelectedDonor; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
// GET: Donation/Edit/5 public ActionResult Edit(int id) { UpdateDonation ViewModel = new UpdateDonation(); string url = "donationdata/finddonation/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Can catch the status code (200 OK, 301 REDIRECT), etc. //Debug.WriteLine(response.StatusCode); if (response.IsSuccessStatusCode) { //Put data into donation data transfer object DonationDto SelectedDonation = response.Content.ReadAsAsync <DonationDto>().Result; ViewModel.donation = SelectedDonation; //get information about donors which could make this donation. url = "donordata/getdonors"; response = client.GetAsync(url).Result; IEnumerable <DonorDto> PotentialDonors = response.Content.ReadAsAsync <IEnumerable <DonorDto> >().Result; ViewModel.alldonors = PotentialDonors; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult FindDonation(int id) { Donation donation = db.Donations.Find(id); if (donation == null) { return(NotFound()); } DonationDto DonationDto = new DonationDto { DonationID = donation.DonationID, FistName = donation.FistName, LastName = donation.LastName, Email = donation.Email, PhoneNumber = donation.PhoneNumber, Address = donation.Address, Country = donation.Country, Zip = donation.Zip, Province = donation.Province, City = donation.City, Amount = donation.Amount, Date = donation.Date, CardName = donation.CardName, CardNumber = donation.CardNumber, ExpiryDate = donation.ExpiryDate, CVV = donation.CVV, CardType = donation.CardType, CompanyName = donation.CompanyName, EventId = donation.EventId }; return(Ok(DonationDto)); }
public IHttpActionResult GetDonations() { //List<Donation> Donations = db.Donations.ToList(); IEnumerable <Donation> Donations = db.Donations.ToList(); List <DonationDto> DonationDtos = new List <DonationDto> { }; //Here you can choose which information is exposed to the API foreach (var Donation in Donations) { DonationDto NewDonation = new DonationDto { DonationId = Donation.DonationId, Date = Donation.Date, Amount = Donation.Amount, OneTime = Donation.OneTime, Msg = Donation.Msg, Dedication = Donation.Dedication, DedicateName = Donation.DedicateName, Action = Donation.Action, Anonymity = Donation.Anonymity, PaymentMethod = Donation.PaymentMethod, PaymentNumber = Donation.PaymentNumber, DonorId = Donation.DonorId }; DonationDtos.Add(NewDonation); } return(Ok(DonationDtos)); }
// GET: Donation/Details/5 public ActionResult Details(int id) { //using view model to detail donation by id REFERENCE teamController in varsity w auth ShowDonation ViewModel = new ShowDonation(); //creating a url string string url = "DonationData/FindDonation/" + id; //sending http request and getting a response back HttpResponseMessage response = client.GetAsync(url).Result; //if statment:: if the call worked return this else return error if (response.IsSuccessStatusCode) { DonationDto SelectedDonation = response.Content.ReadAsAsync <DonationDto>().Result; ViewModel.donation = SelectedDonation; //add the get statement for events related to the donations (id is the donation id that we will use to get details) //REF VIDEO for week 4 before passion project (git code was harder to understand) url = "DonationData/FindEventForDonation" + id;//donation id FYI response = client.GetAsync(url).Result; EventDto SelectedEvent = response.Content.ReadAsAsync <EventDto>().Result; ViewModel.events = SelectedEvent; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult FindDonation(int id) { //find donation data Donation Donation = db.Donations.Find(id); if (Donation == null) { return(NotFound()); } //Put into Dto form DonationDto DonationDto = new DonationDto { DonationId = Donation.DonationId, Date = Donation.Date, Amount = Donation.Amount, OneTime = Donation.OneTime, Msg = Donation.Msg, Dedication = Donation.Dedication, DedicateName = Donation.DedicateName, Action = Donation.Action, Anonymity = Donation.Anonymity, PaymentMethod = Donation.PaymentMethod, PaymentNumber = Donation.PaymentNumber, DonorId = Donation.DonorId }; return(Ok(DonationDto)); }
public ActionResult Details(int id) { ShowDonation ViewModel = new ShowDonation(); ViewModel.isadmin = User.IsInRole("Admin"); string url = "DonationData/FindDonation/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Debug.WriteLine(response.StatusCode); if (response.IsSuccessStatusCode) { DonationDto SelectedDonations = response.Content.ReadAsAsync <DonationDto>().Result; ViewModel.Donation = SelectedDonations; //Find the Event for Donation by Id url = "EventData/FindEventForDonation/" + id; response = client.GetAsync(url).Result; Debug.WriteLine(response.StatusCode); EventDto SelectedEvent = response.Content.ReadAsAsync <EventDto>().Result; ViewModel.events = SelectedEvent; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public ActionResult Update(int id, DonationDto model) { try { Console.WriteLine("Inside Update"); if (model != null) { var dta = donationRepository.Query().FirstOrDefault(x => x.Id == id); dta.InjectFrom <DeepCloneInjection>(model); var selected = dta.DonationDetails.Where(x => x.DonationStatus == Core.Entities.DonationStatus.Requested).Count(); var isRequested = model.DonationDetails != null || (selected + 1) == dta.DonationDetails.Count(); dta.DonationStatus = isRequested ? Core.Entities.DonationStatus.Requested : Core.Entities.DonationStatus.PartialRequested; if (dta.DonationStatus == Core.Entities.DonationStatus.PartialRequested) { var itemId = model.DonationDetails.FirstOrDefault().Id; var line = dta.DonationDetails.FirstOrDefault(x => x.Id == itemId); line.RequestedBy = CurrentUser; line.ModifiedBy = CurrentUser; line.ModifiedOn = DateTime.Now; line.DonationStatus = Core.Entities.DonationStatus.Requested; dta.DonationDetails.Where(x => x.Id == itemId).Select(u => u = line); } donationRepository.Update(dta); Response.StatusCode = (int)HttpStatusCode.OK; } } catch (System.Exception ex) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { status = "error", data = ex.Message })); } return(Json(new { status = "ok", data = model })); }
public IHttpActionResult GetDonations() { List <Donation> donations = db.Donations.ToList(); List <DonationDto> donationDtos = new List <DonationDto> { }; foreach (var donation in donations) { DonationDto NewDonation = new DonationDto { DonationID = donation.DonationID, FistName = donation.FistName, LastName = donation.LastName, Email = donation.Email, PhoneNumber = donation.PhoneNumber, Address = donation.Address, Country = donation.Country, Zip = donation.Zip, Province = donation.Province, City = donation.City, Amount = donation.Amount, Date = donation.Date, CardName = donation.CardName, CardNumber = donation.CardNumber, ExpiryDate = donation.ExpiryDate, CVV = donation.CVV, CardType = donation.CardType, CompanyName = donation.CompanyName, EventId = donation.EventId }; donationDtos.Add(NewDonation); } return(Ok(donationDtos)); }
public void Donate(DonationDto donationDto, int UserId) { Donation donation = new Donation(); donation.UserId = UserId; int donationProgramId = donationDto.donationProgram.DonationProgramId; DonationProgram donationProgram = _context.DonationPrograms.FirstOrDefault(n => n.DonationProgramId == donationProgramId); int NewTotal = donationProgram.Total + donationDto.amount; donationProgram.Total = NewTotal; _context.SaveChanges(); //var donations = _context.DonationProgramAudits.ToList(); var donationProgramAudit = _context.DonationProgramAudits.Where(n => n.DonationProgramId == donationProgramId).ToList().Last(); donation.DonationProgram_AuditId = donationProgramAudit.DonationProgram_AuditId; donation.Amount = donationDto.amount; _context.Donations.Add(donation); }
public async Task PublishCreatedDonation(DonationDto donation) { if (donation == null) { throw new ArgumentNullException(nameof(donation)); } await Clients.All.SendAsync("ReceiveNewDonation", donation); }
public async Task <DonationResultDto> DonateAsync(string id, DonationDto dto) { var user = await _unitOfWork.UserRepository.FindAll(x => x.Id.Equals(id)) .Include(x => x.UserDetail) .FirstOrDefaultAsync(); if (user == null) { throw new NotFoundException("User not found."); } user.TotalBalance += dto.Amount; await _unitOfWork.CommitAsync(); var parent = await _unitOfWork.UserRepository.FindAll(x => x.Id.Equals(dto.CreatedBy)).Include(x => x.UserDetail).SingleOrDefaultAsync(); _queue.QueueBackgroundWorkItem(async(serviceFactory) => { await _emailSender.SendEmailAsync(new Message { Subject = "Donation inform", Emails = new string[] { dto.Email }, Body = HtmlParser.GenerateBody(new DonationTmpl(dto.SenderName, $"{user.UserDetail.FirstName} {user.UserDetail.LastName}", dto.Amount.ToString())) }); await _emailSender.SendEmailAsync(new Message { Subject = "Donation inform", Emails = new string[] { parent.Email }, Body = HtmlParser.GenerateBody(new DonationMailToParentTmpl($"{parent.UserDetail.FirstName} {parent.UserDetail.LastName}", dto.SenderName, $"{user.UserDetail.FirstName} {user.UserDetail.LastName}", dto.Amount.ToString())) }); }); await _memoryService.CreateFeedAsync(new CreateFeedDto { Content = $"{dto.SenderName} just invested in {user.UserDetail.FirstName}'s future!", FeedType = FeedType.Donation, UserSlug = user.Slug, FileUrl = $"{ApiUrl}/assets/jar.png" }); var donationResultDto = new DonationResultDto { IsSuccess = true, CurrentAmount = user.TotalBalance }; return(donationResultDto); }
public IHttpActionResult CreateDonation(DonationDto donationDto) { if (!ModelState.IsValid) { return(BadRequest()); } var donation = Mapper.Map <DonationDto, Donation>(donationDto); _context.Donations.Add(donation); _context.SaveChanges(); donationDto.ID = donation.ID; return(Created(new Uri(Request.RequestUri + "/" + donation.ID), donationDto)); }
public Donation Donate([FromBody] DonationDto donationDto, int id) { var donation = new Donation { Amount = donationDto.Amount, CompanyId = id, FromId = this.GetUserId(), CreatedAt = DateTime.Now, }; _context.Donations.Add(donation); _context.SaveChanges(); return(donation); }
public ActionResult DeleteConfirm(int id) { string url = "DonationData/FindDonation/" + id; //sending HTTP request HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { DonationDto Selecteddonation = response.Content.ReadAsAsync <DonationDto>().Result; return(View(Selecteddonation)); } else { return(RedirectToAction("Error")); } }
public async Task GetDonation_ShouldReturnDonation() { var testGuid = new Guid("507f77df-fd1c-48c5-9900-f7ace8c250f7"); var actual = new DonationDto() { Id = new Guid("507f77df-fd1c-48c5-9900-f7ace8c250f7"), Amount = 300m, Currency = LiqPayCurrency.UAH, LiqpayOrderId = "testLiqPayOrderId1" }; var result = await _donationService.GetDonation(testGuid); result.Should().BeEquivalentTo(actual); }
public ActionResult DeleteConfirm(int id) { string url = "DonationData/FindDonation/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Debug.WriteLine(response.StatusCode); if (response.IsSuccessStatusCode) { DonationDto SelectedDonations = response.Content.ReadAsAsync <DonationDto>().Result; return(View(SelectedDonations)); } else { return(RedirectToAction("Error")); } }
// Put public void UpdateDonation(int id, DonationDto donationDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var dbDonation = _context.Donations.FirstOrDefault(x => x.ID == id); if (dbDonation == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Mapper.Map(donationDto, dbDonation); _context.SaveChanges(); }
// GET: Donation/Delete/5 public ActionResult DeleteConfirm(int id) { string url = "donationdata/finddonation/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Can catch the status code (200 OK, 301 REDIRECT), etc. //Debug.WriteLine(response.StatusCode); if (response.IsSuccessStatusCode) { //Put data into player data transfer object DonationDto SelectedDonation = response.Content.ReadAsAsync <DonationDto>().Result; return(View(SelectedDonation)); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult GetAllDonations() { //List of donations List <Donation> Donations = db.donations.ToList(); //using view model :: show donation List <ListDonation> DonationDtos = new List <ListDonation> { }; //information to be displayed foreach (var Donation in Donations) { ListDonation donation = new ListDonation(); //getting events from the events table and linking it to the donations table Event Event = db.events .Where(e => e.Donations.Any(d => d.EventId == Donation.EventId)) .FirstOrDefault(); //now calling the events dto to fetch the information to list EventDto NewEvent = new EventDto { EventId = Event.EventId, Title = Event.Title }; //now calling the donations dto to fetch the data DonationDto NewDonation = new DonationDto { donationId = Donation.donationId, firstName = Donation.firstName, lastName = Donation.lastName, email = Donation.email, phoneNumber = Donation.phoneNumber, amount = Donation.amount, //add event id EventId = Donation.EventId, }; donation.Event = NewEvent; DonationDtos.Add(donation); } return(Ok(DonationDtos)); }
public IHttpActionResult UpdateDonation(int id, DonationDto donationDto) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var donationInDb = _context.Items.SingleOrDefault(i => i.Id == id); if (donationInDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } Mapper.Map(donationDto, donationInDb); _context.SaveChanges(); return(Ok()); }
public IHttpActionResult GetDonations() { List <Donation> donations = db.Donations.ToList(); List <DonationDto> donationDtos = new List <DonationDto>(); foreach (var donation in donations) { DonationDto NewDonation = new DonationDto { DonationID = donation.DonationID, DonationAmount = donation.DonationAmount, DonationDate = donation.DonationDate, DonationMethod = donation.DonationMethod, DonationText = donation.DonationText }; donationDtos.Add(NewDonation); } return(Ok(donationDtos)); }
public HttpResponseMessage MakeDonation(DonationDto donationDto, int UserId) { try { if (UserId != 0) { _rotaractRepository.Donate(donationDto, UserId); } else { _rotaractRepository.Donate(donationDto, 0); } _rotaractRepository.Save(); return(Request.CreateResponse(HttpStatusCode.Accepted, "Donation Made")); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e)); } }
public IHttpActionResult GetDonationsForEvent(int id) { //ERROR IN CONTROLLER List <Donation> Donations = db.Donations.Where(p => p.EventId == id).ToList(); List <DonationDto> DonationDtos = new List <DonationDto> { }; //Here you can choose which information is exposed to the API foreach (var Donation in Donations) { DonationDto NewDonation = new DonationDto { FistName = Donation.FistName, LastName = Donation.LastName }; DonationDtos.Add(NewDonation); } return(Ok(DonationDtos)); }
public void MakeDonation_ShouldAllowAnUserToDonateREPO() { //declare and init var mockDonationProgram = new DonationProgram { DonationProgramId = 1, DonationProgramName = "One", Description = "Maxim one", ImageRef = "An image ref", StartDate = DateTime.Now, EndDate = DateTime.Now, Total = 111 }; const int AmountToDonate = 20; const int UserID = 1234; var mockExpected = new DonationDto() { donationProgram = mockDonationProgram, amount = AmountToDonate }; var mockRepo = new Mock <IRotaractRepository>(); mockRepo.Setup(d => d.Donate(mockExpected, UserID)); //Arrange DonationController donationController = new DonationController(mockRepo.Object) { Request = new System.Net.Http.HttpRequestMessage(), Configuration = new HttpConfiguration() }; //Act var result = donationController.MakeDonation(mockExpected, UserID); //Assert Assert.AreEqual(HttpStatusCode.Accepted, result.StatusCode); }
public Task <DonationDto> RequestedBy(int donationId) { var dta = donationRepository.GetById(donationId); DonationDto dto = null; try { if (dta != null) { dta.RequestedBy = CurrentUser; dta.ModifiedBy = CurrentUser; dta.ModifiedOn = DateTime.Now; donationRepository.Update(dta); dto = (DonationDto) new DonationDto().InjectFrom <DeepCloneInjection>(dta); } } catch (System.Exception) { throw; } return(Task.FromResult <DonationDto>(dto)); }