/// <summary> /// Gets Donations from PCO. /// </summary> /// <param name="modifiedSince">The modified since.</param> /// <returns></returns> private static List <DonationDTO> GetDonations(DateTime?modifiedSince) { var donations = new List <DonationDTO>(); var apiOptions = new Dictionary <string, string> { { "include", "designations" }, { "per_page", "100" } }; var donationsQuery = GetAPIQuery(ApiEndpoint.API_DONATIONS, apiOptions, modifiedSince); if (donationsQuery == null) { return(donations); } foreach (var item in donationsQuery.Items) { var donation = new DonationDTO(item, donationsQuery.IncludedItems); if (donation != null) { donations.Add(donation); } } return(donations); }
public static FinancialTransaction Translate(DonationDTO inputTransaction) { var currencyType = CurrencyType.Unknown; switch (inputTransaction.PaymentMethod) { case "cash": currencyType = CurrencyType.Cash; break; case "check": currencyType = CurrencyType.Check; break; case "credit card": currencyType = CurrencyType.CreditCard; break; case "debit card": currencyType = CurrencyType.CreditCard; break; case "card": currencyType = CurrencyType.CreditCard; break; case "ach": currencyType = CurrencyType.ACH; break; case "non-cash": currencyType = CurrencyType.NonCash; break; } var transactionCode = string.Empty; if (inputTransaction.PaymentMethod == "check") { transactionCode = inputTransaction.PaymentCheckNumber; } else if (inputTransaction.PaymentMethod != "cash") { transactionCode = inputTransaction.PaymentLastFour; } var transaction = new FinancialTransaction { Id = inputTransaction.Id, TransactionDate = inputTransaction.ReceivedAt, AuthorizedPersonId = inputTransaction.PersonId, CreatedDateTime = inputTransaction.CreatedAt, ModifiedDateTime = inputTransaction.UpdatedAt, CurrencyType = currencyType, TransactionCode = transactionCode, BatchId = (inputTransaction.BatchId.HasValue) ? inputTransaction.BatchId.Value : default(int) }; return(transaction); }
public void MakeDonation(DonationDTO donationDto) { Dog dog = Database.Dogs.Get(donationDto.Id); Donation donat = new Donation { Id = donationDto.Id, Sum = donationDto.Sum, PhoneNumber = donationDto.PhoneNumber, Address = donationDto.Address, Gift = false, GiftType = "", DogId = donationDto.DogId, Dog = dog, Date = donationDto.Date }; if (dog == null) { throw new ValidationException("Dog wasn't selected", ""); } bool gift = new GiftClass().givingGift(donat); donat.Gift = gift; Database.Donations.Create(donat); Database.Save(); }
public async Task <DonationDTO> Edit(DonationDTO dto) { dto.UserId = Session.UserId; var donation = dto.MapTo <TDonation>(); await donationRepository.Edit(donation, Session); return(donation.MapTo <DonationDTO>()); }
public Guid Insert(DonationDTO donationDto) { Console.WriteLine("INSERT APPLICATION DONATION"); var donation = DonationAdapter.ToDomain(donationDto); return(donationRepository.Insert(donation)); }
public ResultBM GetDonation(int donationId) { try { VolunteerBLL volunteerBll = new VolunteerBLL(); ResultBM volunteerResult = null; VolunteerBM volunteerBm = null; DonationStatusBLL donationStatusBll = new DonationStatusBLL(); ResultBM statusResult = null; DonorBLL donorBll = new DonorBLL(); ResultBM donorResult = null; DonationDAL donationDal = new DonationDAL(); DonationBM donationBm = null; DonationDTO donationDto = donationDal.GetDonation(donationId); //Si la donación existe, debería existir el estado if (donationDto != null) { statusResult = donationStatusBll.GetDonationStatus(donationDto.statusId); if (!statusResult.IsValid()) { return(statusResult); } if (statusResult.GetValue() == null) { throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " statusId " + donationDto.statusId); } donorResult = donorBll.GetDonor(donationDto.donorId); if (!donorResult.IsValid()) { return(donorResult); } if (donorResult.GetValue() == null) { throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " donorId " + donationDto.donorId); } //Podría no existir voluntario, sobre todo si se consulta una donación recién creada volunteerResult = volunteerBll.GetVolunteer(donationDto.volunteerId); if (volunteerResult.GetValue() != null) { volunteerBm = volunteerResult.GetValue <VolunteerBM>(); } donationBm = new DonationBM(donationDto, donorResult.GetValue <DonorBM>(), statusResult.GetValue <DonationStatusBM>(), volunteerBm); } return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", donationBm)); } catch (Exception exception) { return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception)); } }
public async Task <IActionResult> PutDonation(DonationDTO donationDto) { var donation = await donationService.Edit(donationDto); if (donation == null) { return(BadRequest()); } return(Ok(donation)); }
public DonationBM(DonationDTO donationDto, DonorBM donorBm, DonationStatusBM donationStatusBm = null, VolunteerBM volunteerBm = null) { this.id = donationDto.id; this.items = donationDto.items; this.arrival = donationDto.arrival; this.donationStatus = donationStatusBm; this.donor = donorBm; this.comment = donationDto.comment; this.volunteer = volunteerBm; this.stocked = donationDto.stocked; }
//No está bueno esto, pero me permite recuperar el voluntario. Poco performante... pero no hay tiempo. private VolunteerBM GetVolunteer(DonationDTO donationDto) { if (donationDto.volunteerId > 0) { ResultBM volunteerResult = new VolunteerBLL().GetVolunteer(donationDto.volunteerId); return(volunteerResult.GetValue <VolunteerBM>()); } else { return(null); } }
public ActionResult DonationFailed() { if (Session["DonatedInfo"] != null) { //Get data in session and transactiondetail var newDonate = (DonationDTO)Session["DonatedInfo"]; Session.Remove("DonatedInfo"); return(PartialView("~/Views/Donation/_DonationFailed.cshtml", newDonate)); } var emptyDonate = new DonationDTO(); return(PartialView("~/Views/Donation/_DonationFailed.cshtml", emptyDonate)); }
/// <summary> /// Get info then redirect to NganLuong /// </summary> /// <param name="inputData"></param> /// <returns></returns> public ActionResult CheckOutNganLuong(NganLuongCheckOut inputData) { //get data from form string payment_method = inputData.option_payment; string str_bankcode = inputData.bankcode; bool isPublic = inputData.isPublic != "0"; var numberofMoney = inputData.numberMoney == "0" ? inputData.inputMoney : inputData.numberMoney; //set data to nganluongAPI RequestInfo info = new RequestInfo { Merchant_id = WsConstant.NganLuongApi.MerchantId, Merchant_password = WsConstant.NganLuongApi.Password, Receiver_email = WsConstant.NganLuongApi.AdminEmail, cur_code = "vnd", bank_code = str_bankcode, Order_code = "chuyen_khoan_ung_ho", Total_amount = numberofMoney, fee_shipping = "0", Discount_amount = "0", order_description = "Chuyển tiền ủng hộ thông qua Ngân Lượng", return_url = "http://localhost:2710/#/DonationComplete", cancel_url = "http://localhost:2710/#/DonationFailed", Buyer_fullname = inputData.buyer_fullname, Buyer_email = inputData.buyer_email, Buyer_mobile = inputData.buyer_mobile }; APICheckoutV3 objNLChecout = new APICheckoutV3(); ResponseInfo result = objNLChecout.GetUrlCheckout(info, payment_method); //get and set data to session var newDonate = new DonationDTO(); newDonate.IsPublic = isPublic; newDonate.DonatedMoney = decimal.Parse(numberofMoney); newDonate.TradeCode = result.Token; newDonate.UserId = inputData.DonateUserId; newDonate.EventId = inputData.DonateEventId; newDonate.Content = inputData.DonateContent; Session["DonatedInfo"] = newDonate; //return to checkout page or error page if (result.Error_code == "00") { return(Redirect(result.Checkout_url)); //return Redirect("http://localhost:2710/#/DonationComplete"); //return Redirect("http://localhost:2710/#/DonationFailed"); } else { return(PartialView("~/Views/Error/_Error.cshtml")); } }
public async Task <IActionResult> Donate([FromBody] DonationDTO donation) { try { if (!ModelState.IsValid) { _logger.LogTrace("New donation could not be delivered due to invalid parameters.", donation); return(BadRequest("Donation details invalid.")); } string username = User.Identity.Name; ApplicationUser user = null; if (username == null) { _logger.LogInformation("New donation from unidentified user."); } else { user = await _unitOfWork.UserManager.FindByNameAsync(username).ConfigureAwait(false); } var emailData = new InternalDonationTemplate() { Amount = donation.Currency + donation.Amount, Username = user != null ? user.UserName : "******", IPAddress = _ipService.GetIPAddress(HttpContext) }; var internalEmailResponse = await _emailSender .SendEmailAsync("*****@*****.**", _config["SendGrid:Templates:InternalDonation"], EmailFrom.Admin, emailData) .ConfigureAwait(false); if (internalEmailResponse.StatusCode == System.Net.HttpStatusCode.Accepted) { _logger.LogInformation("New donation received."); return(NoContent()); } else { _logger.LogError("New donation received but internal email dispatch failed."); return(StatusCode(500, "Donation received.")); } } catch (Exception ex) { _logger.LogError(ex, "Donation received."); return(StatusCode(500, "Donation received.")); } }
public async Task <object> UpdateDonation(DonationDTO donationDTO, Guid Id) { try { var update = await dataContext.Donations.Where(p => p.Id == Id).FirstOrDefaultAsync(); if (update != null) { update.Amount = donationDTO.Amount; update.AccountType = donationDTO.AccountType; update.Annonymous = donationDTO.Annonymous; update.CardNumber = donationDTO.CardNumber; update.CVV = donationDTO.CVV; update.Email = donationDTO.Email; update.ExpiryDate = donationDTO.ExpiryDate; update.Name = donationDTO.Name; update.Pin = donationDTO.Pin; int result = await dataContext.SaveChangesAsync(); if (result > 0) { res.Success = true; res.Message = "Donation successfully updated"; res.Data = update; return(res); } else { res.Success = false; res.Message = "Db Error"; return(res); } } else { res.Success = false; res.Message = "Donation id does not exist"; res.Data = null; return(res); } } catch (Exception ex) { throw new Exception(ex.Message); } }
private void ConfirmRefundCorrect(DonationDTO donation) { // Refund amount should already be negative (when the original donation was reversed), but negative-ify it just in case if (donation.Status != DonationStatus.Refunded || donation.Amount <= 0) { return; } donation.Amount *= -1; donation.Distributions.All(dist => { dist.Amount *= -1; return(true); }); }
public bool UpdateDonation(DonationDTO donationDto) { DBSql dbsql = new DBSql(); String sql; sql = "UPDATE donation SET "; sql += "items = " + donationDto.items + ", "; sql += "statusId = " + donationDto.statusId + ", "; sql += "donorId = " + donationDto.donorId + ", "; sql += "comment = '" + donationDto.comment + "', "; sql += "volunteerId = " + (donationDto.volunteerId == 0 ? "null" : donationDto.volunteerId.ToString()) + " "; sql += "WHERE id = " + donationDto.id; dbsql.ExecuteNonQuery(sql); return(true); }
public async Task <ActionResult <DonationDTO> > PostDonation(DonationDTO donationDto) { try { var ilyes = donationDto; int i = 10; var donation = await donationService.Edit(donationDto); i = 20; return(Ok(donation)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
private DonationDTO Resolve(List <String> item) { DonationDTO result = new DonationDTO(); result.id = int.Parse(item[0]); result.items = int.Parse(item[1]); result.arrival = DateTime.Parse(item[2]); result.statusId = int.Parse(item[3]); result.donorId = int.Parse(item[4]); result.comment = item[5]; result.volunteerId = int.Parse(item[6].Length == 0 ? "0" : item[6]); //No forma parte del modelo de datos per sé result.stocked = int.Parse(item[7]); return(result); }
//public List<DonationDAL> GetDonationHistoryOfUser(int userId) //{ //} public DonationDTO GetFullInformationOfDonation(int donationId) { DonationDTO currentDonation = new DonationDTO(); try { Donation donation; string userName = ""; string userImageUrl = ""; using (var db = new Ws_DataContext()) { donation = db.Donations.FirstOrDefault(x => x.DonationId == donationId); var wsUser = db.Ws_User.FirstOrDefault(x => x.UserID == donation.UserId); if (wsUser != null) { userName = wsUser.UserName; } var userInformation = db.User_Information.FirstOrDefault(x => x.UserID == donation.UserId); if (userInformation != null) { userImageUrl = userInformation.ProfileImage; } } using (var db = new EventDAL()) { currentDonation.EventBasicInformation = db.GetFullEventBasicInformation(donation.EventId); } currentDonation.DonationId = donation.DonationId; currentDonation.UserId = donation.UserId; currentDonation.UserName = userName; currentDonation.UserImageUrl = userImageUrl; currentDonation.EventId = donation.EventId; currentDonation.TradeCode = donation.TradeCode; currentDonation.DonatedMoney = donation.DonatedMoney; currentDonation.Content = donation.Content; currentDonation.DonatedDate = donation.DonatedDate.ToString("hh:mm:ss dd/MM/yy"); currentDonation.IsPublic = donation.IsPublic; } catch (Exception) { //throw; } return(currentDonation); }
public async Task <IActionResult> UpdateDonation(DonationDTO donationDTO, Guid Id) { try { dynamic result = await _donation.UpdateDonation(donationDTO, Id); if (result.Success == false) { return(BadRequest(result)); } return(Ok(result)); } catch (Exception ex) { throw new Exception(); } }
public bool AddNewDonation(DonationDTO donationInfo) { using (var db = new Ws_DataContext()) { var newDonate = db.Donations.Create(); newDonate.UserId = donationInfo.UserId; newDonate.EventId = donationInfo.EventId; newDonate.TradeCode = donationInfo.TradeCode; newDonate.DonatedMoney = donationInfo.DonatedMoney; newDonate.Content = donationInfo.Content; newDonate.IsPublic = donationInfo.IsPublic; newDonate.DonatedDate = DateTime.Now;; db.Donations.Add(newDonate); db.SaveChanges(); return(true); } }
public DonationDTO GetDonationByProcessorPaymentId(string processorPaymentId) { var d = _mpDonationRepository.GetDonationByProcessorPaymentId(processorPaymentId); if (d == null) { return(null); } var donation = new DonationDTO { Amount = d.donationAmt, Id = d.donationId + "", BatchId = d.batchId, Status = (DonationStatus)d.donationStatus }; return(donation); }
public async Task <IActionResult> Donation(string CauseId, DonationDTO donationDTO) { try { var UserId = "B7C60175-B370-4CE4-AC86-08D81D38F5FE"; donationDTO.UserId = UserId; dynamic result = await _donation.AddDonation(donationDTO, CauseId); if (result.Success == false) { return(BadRequest(result)); } return(Ok(result)); } catch (Exception ex) { throw new Exception(); } }
public static List <FinancialTransactionDetail> Translate(DonationDTO inputDonation) { var transactionDetails = new List <FinancialTransactionDetail>(); foreach (var inputTransactionDetail in inputDonation.Designations) { var transactionDetail = new FinancialTransactionDetail { Id = inputTransactionDetail.Id, AccountId = inputTransactionDetail.FundId, Amount = Convert.ToDecimal(inputTransactionDetail.AmountCents.Value / 100.00), TransactionId = inputDonation.Id, CreatedDateTime = inputDonation.CreatedAt, ModifiedDateTime = inputDonation.UpdatedAt }; transactionDetails.Add(transactionDetail); } return(transactionDetails); }
private Guid Insert(Donation donation) { Console.WriteLine("POST DONATION INSERT CONTROLLER"); List <AffinityDTO> affinities = new List <AffinityDTO>(); foreach (var affinity in donation.Affinities) { AffinityDTO affinityDTO = new AffinityDTO() { AffinityId = affinity.AffinityId, Name = affinity.Name }; affinities.Add(affinityDTO); } DonationDTO donationDto = new DonationDTO() { DonationId = donation.DonationId, UserId = donation.UserId, Title = donation.Title, Description = donation.Description, Quantity = donation.Quantity, TakeDonation = donation.TakeDonation, Affinities = affinities, Address = new AddressDTO() { AddressId = donation.Address.AddressId, CEP = donation.Address.CEP, Avenue = donation.Address.Avenue, Number = donation.Address.Number, Neighborhood = donation.Address.Neighborhood, City = donation.Address.City, State = donation.Address.State } }; return(DonationApplication.Insert(donationDto)); }
private StripeCharge GetStripeCharge(DonationDTO donation) { if (string.IsNullOrWhiteSpace(donation.Source.PaymentProcessorId)) { return(null); } // If it is a positive amount, it means it's a Charge, otherwise it's a Refund if (donation.Amount >= 0) { return(_paymentService.GetCharge(donation.Source.PaymentProcessorId)); } var refund = _paymentService.GetRefund(donation.Source.PaymentProcessorId); if (refund != null && refund.Charge != null) { return(refund.Charge); } return(null); }
public ResultBM UpdateDonation(DonationBM donationBm) { try { DonationDAL donationDal = new DonationDAL(); DonationDTO donationDto; ResultBM validationResult = IsValid(donationBm); if (!validationResult.IsValid()) { return(validationResult); } donationDto = new DonationDTO(donationBm.Items, donationBm.Arrival, donationBm.donationStatus.id, donationBm.donor.donorId, donationBm.Comment, donationBm.volunteer == null ? 0 : donationBm.volunteer.volunteerId, donationBm.id); donationDal.UpdateDonation(donationDto); return(new ResultBM(ResultBM.Type.OK, "Se ha actualizado la donación.", donationBm)); } catch (Exception exception) { return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("UPDATING_ERROR") + " " + exception.Message, exception)); } }
public void SetDonationSource(DonationDTO donation, StripeCharge charge) { if (donation.Source.SourceType == PaymentType.Cash) { donation.Source.AccountHolderName = "cash"; } else if (charge != null && charge.Source != null) { donation.Source.AccountNumberLast4 = charge.Source.AccountNumberLast4; if (donation.Source.SourceType != PaymentType.CreditCard || charge.Source.Brand == null) { return; } switch (charge.Source.Brand) { case CardBrand.AmericanExpress: donation.Source.CardType = CreditCardType.AmericanExpress; break; case CardBrand.Discover: donation.Source.CardType = CreditCardType.Discover; break; case CardBrand.MasterCard: donation.Source.CardType = CreditCardType.MasterCard; break; case CardBrand.Visa: donation.Source.CardType = CreditCardType.Visa; break; default: donation.Source.CardType = null; break; } } }
public bool SaveDonation(DonationDTO donationDto) { DBSql dbsql = new DBSql(); String sql; sql = "INSERT INTO donation (items, arrival, statusId, donorId, comment, volunteerId) VALUES ("; sql += donationDto.items + ", "; sql += "GETDATE(), "; sql += donationDto.statusId + ", "; sql += donationDto.donorId + ", "; sql += "'" + donationDto.comment + "', "; if (donationDto.volunteerId != 0) { sql += donationDto.volunteerId; } else { sql += "null"; } sql += ");SELECT @@IDENTITY"; donationDto.id = dbsql.ExecuteNonQuery(sql); return(true); }
/// <summary> /// Get top recently donted user /// </summary> /// <param name="top"></param> /// <returns></returns> public List <DonationDTO> GetTopRecentlyDonator(int top) { List <DonationDTO> recentDonation = new List <DonationDTO>(); try { List <int> donationIdList; using (var db = new Ws_DataContext()) { donationIdList = db.Donations.OrderByDescending(x => x.DonatedDate).Select(x => x.DonationId).Take(top).ToList(); } foreach (var donationId in donationIdList) { DonationDTO donation = GetFullInformationOfDonation(donationId); recentDonation.Add(donation); } } catch (Exception) { //throw; } return(recentDonation); }
public static Donation ToDomain(DonationDTO donationDTO) { return(new Donation() { DonationId = donationDTO.DonationId, UserId = donationDTO.UserId, Title = donationDTO.Title, Description = donationDTO.Description, Quantity = donationDTO.Quantity, TakeDonation = donationDTO.TakeDonation, Affinities = AffinityAdapter.ListToDomain(donationDTO.Affinities), Address = new Address() { AddressId = donationDTO.Address.AddressId, CEP = donationDTO.Address.CEP, Avenue = donationDTO.Address.Avenue, Number = donationDTO.Address.Number, Neighborhood = donationDTO.Address.Neighborhood, City = donationDTO.Address.City, State = donationDTO.Address.State } }); }