Example #1
0
        public async Task <Response <string> > GetEstimatedFee(DonateViewModel model)
        {
            var response  = new Response <string>();
            var test      = model.Amount;
            var callInput = new CallInput()
            {
                From  = model.Address,
                To    = model.Campaign,
                Value = new HexBigInteger(new BigInteger(model.Amount))
            };

            try
            {
                var gas = await _gethClient.Web3.Eth.Transactions.EstimateGas.SendRequestAsync(callInput);

                var gasPrice = await _gethClient.Web3.Eth.GasPrice.SendRequestAsync();

                var gasPriceEth = Web3.Convert.FromWei(gasPrice);

                var estimatedFee = (decimal)gas.Value * gasPriceEth;

                response.Value     = estimatedFee + " Eth";
                response.Succeeded = true;
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.Succeeded = false;
            }

            return(response);
        }
 public IActionResult Donate()
 {
     try
     {
         // Prepare ViewModel with categories and institutions to be used when user makes a selection
         var categories = JsonConvert.SerializeObject(
             _donationService.GetCategoryList(),
             new JsonSerializerSettings()
         {
             ReferenceLoopHandling = ReferenceLoopHandling.Ignore
         });
         var institutions = JsonConvert.SerializeObject(
             _donationService.GetInstitutionList(take: 0),
             new JsonSerializerSettings()
         {
             ReferenceLoopHandling = ReferenceLoopHandling.Ignore
         });
         var model = new DonateViewModel()
         {
             Institutions = JsonConvert.DeserializeObject <List <InstitutionViewModel> >(institutions),
             Categories   = JsonConvert.DeserializeObject <List <CategoryViewModel> >(categories),
         };
         if (model.PickUpDateOn == DateTime.MinValue)
         {
             model.PickUpDateOn = DateTime.Now.AddDays(3);
         }
         return(View(model));
     }
     catch (Exception e)
     {
         _logger.LogError(e, "Error in {Action}", nameof(Donate));
         throw;
     }
 }
Example #3
0
        public async Task <IActionResult> Index(DonateViewModel model)
        {
            if (model.UserName == null)
            {
                model.IsAnonymous = true;
            }
            var request = _mapper.Map <MakeDonationRequest>(model);

            if (!request.IsAnonymous)
            {
                if (HttpContext.User.Claims.Any(c => c.Type == ClaimTypes.Sid))
                {
                    request.UserKey = Guid.Parse(HttpContext.User.Claims.Single(c => c.Type == ClaimTypes.Sid).Value);
                }
                else
                {
                    request.UserKey = null;
                }
            }
            var response = await _bus.RequestAsync(request);

            if (response.IsRequestSuccessful)
            {
                var viewModel = _mapper.Map <DonateResultViewModel>(response);

                return(View("_ThankYou", viewModel));
            }

            HttpContext.Response.StatusCode = 400;
            return(Content("Something has gone wrong"));
        }
        public ActionResult Donate(DonateViewModel model)
        {
            try
            {
                if (context.Users.Where(u => u.Email == model.User.Email && u.Password == model.User.Password).Count() > 0)
                {
                    User user = context.Users
                                .Where(u => u.Email == model.User.Email && u.Password == model.User.Password)
                                .FirstOrDefault();

                    Donor donor = new Donor()
                    {
                        BloodId = model.BloodId,
                        UserId  = user.UserId
                    };

                    context.Donors.Add(donor);
                    context.SaveChanges();

                    return(RedirectToAction("AllDonor", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Either email address or password is incorrect.");
                    model.Blood = context.Bloods.ToList();
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Donate", "Home"));
            }
        }
Example #5
0
        public DonateViewModel AddDonation(DonateViewModel item)
        {
            var itemToAdd = new Donation
            {
                OrderId       = new Guid(item.OrderId),
                Amount        = item.Amount,
                BankAccountId = item.BankAccountId,
                CurrencyId    = item.CurrencyId,
                Description   = item.Description,
                UserId        = item.UserId,
                TargetId      = item.TargetId,
                DonatorEmail  = item.DonatorEmail
            };
            var created = _unitOfWork.DonationRepository.Create(itemToAdd);

            _unitOfWork.SaveChanges();
            var result = new DonateViewModel
            {
                OrderId       = created.OrderId.ToString(),
                Amount        = created.Amount,
                BankAccountId = created.BankAccountId,
                CurrencyId    = created.CurrencyId,
                Description   = created.Description,
                UserId        = created.UserId,
                TargetId      = created.TargetId,
                DonatorEmail  = created.DonatorEmail
            };

            return(result);
        }
        public ActionResult Index()
        {
            if (User == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            IEnumerable <DataAccessLayer.DonationAppointment> donation = _donationAppointmentService.GetDonationsForUser(User.Identity.GetUserId());
            DateTime?LastDonation = null;

            if (donation != null)
            {
                foreach (var current in donation.Reverse())
                {
                    if (current.Confirmed == true)
                    {
                        LastDonation = current.AppointmentDate;
                    }
                }
            }

            DonateViewModel model = new DonateViewModel();

            model = new DonateViewModel()
            {
                LastDonation    = LastDonation,
                AppointmentDate = DateTime.Today,
                Transfusion     = -1,
                RequestId       = -1
            };

            return(View(model));
        }
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            _donate = e.Parameter as DonateViewModel;
            InitProgressBar.Visibility = Windows.UI.Xaml.Visibility.Visible;
            await _donate.InitializationAsyn();

            InitProgressBar.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            ListViewDonate.ItemsSource = _donate.Items;
        }
        public ActionResult Donate()
        {
            DonateViewModel model = new DonateViewModel
            {
                Blood = context.Bloods.ToList()
            };

            return(View(model));
        }
        public async Task <IActionResult> Donate(DonateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var response = await _blockchainService.Donate(model);

                return(Json(response));
            }
            return(Json("Fail"));
        }
 private MainViewModel()
 {
     Costs      = new ObservableCollection <CostViewModel>();
     Categories = new ObservableCollection <CategoryViewModel>();
     DbWorker   = DbWorker.Current;
     Accounts   = new AccountsViewModel();
     Diagram    = new DiagramViewModel();
     OneDrive   = new OneDriveViewModel();
     Donate     = new DonateViewModel();
 }
        public async Task <IActionResult> Index()
        {
            var campaings = await _blockchainService.GetCampaigns();

            var model = new DonateViewModel
            {
                Campaigns = campaings.Value
            };

            return(View(model));
        }
        public ActionResult Donate(DonateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", model));
            }
            bool ok = true;
            IEnumerable <DataAccessLayer.DonationAppointment> donation = _donationAppointmentService.GetDonationsForUser(User.Identity.GetUserId());

            if (donation != null)
            {
                foreach (var current in donation.Reverse())
                {
                    if (current.Confirmed == false)
                    {
                        ok = false;
                    }
                }
            }

            if (ok == false)
            {
                ModelState.AddModelError(String.Empty, "You cannot donate again, you have already an appointment scheduled");
                return(View("Index", model));
            }

            if (model.LastDonation != null && DateTime.Today < model.LastDonation.Value.AddDays(56))
            {
                ModelState.AddModelError(String.Empty, "You cannot donate right now, please wait 56 days since your last donation");
                return(View("Index", model));
            }
            else if (model.AppointmentDate < DateTime.Today)
            {
                ModelState.AddModelError(String.Empty, "You cannot donate before today's date");
                return(View("Index", model));
            }
            else
            {
                if (model.RequestId < 0)
                {
                    _donationAppointmentService.Add(model.AppointmentDate, null, false, User.Identity.GetUserId(), model.Transfusion);
                }
                else
                {
                    _donationAppointmentService.Add(model.AppointmentDate, model.RequestId, false, User.Identity.GetUserId(), model.Transfusion);
                }
            }


            return(View("Index", model));
        }
Example #13
0
        public async Task <IActionResult> Donate(DonateViewModel viewModel)
        {
            var user = await userManager.GetUserAsync(User);

            var accounts = await dbContext.Accounts.Where(x => x.OwnerId == user.Id).ToListAsync();

            foreach (var account in accounts)
            {
                account.Balance = 0;
            }
            await dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(HomeController.Index), "Home"));
        }
        public IActionResult Donate(DonateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (IsModelValid(model, out _errors))
            {
                return(View("Summary", model));
            }
            _errors.ForEach(e => ModelState.AddModelError("", e));

            return(View(model));
        }
Example #15
0
        public ActionResult Index(DonateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (Donate(model.Amount, model.To))
            {
                return(RedirectToAction("Thanks", "Home", new { query = IdentityHelper.GetUserFullNameByEmail(model.To) }));
            }

            ModelState.AddModelError("Amount", "You don't have this amount of bitcoins");

            return(View(model));
        }
        public async Task <IActionResult> Confirmation(DonateViewModel model)
        {
            if (model.Command == "Edit")
            {
                return(View("Donate", model));
            }

            // Prepare Donation object for save to database
            var donationJson = JsonConvert.SerializeObject(
                model,
                new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });
            var donation = JsonConvert.DeserializeObject <DonationModel>(donationJson);

            donation.PickUpOn = model.PickUpDateOn.AddHours(model.PickUpTimeOn.Hour).AddMinutes(model.PickUpTimeOn.Hour);

            // Create list of categories beeing in relation with the donation
            var categoryIds = new List <int>();

            model.Categories.Where(x => x.IsChecked).ToList().ForEach(c => categoryIds.Add(c.Id));

            // Find authenticated user Id. Add relation Donation-User
            //string userId;
            if (User.Identity.IsAuthenticated)
            {
                string userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
                var    user   = _userManager.FindByIdAsync(userId).Result;
                donation.User = user;
            }

            var createDonationTask = _donationService.CreateDonationAsync(donation, model.InstitutionId, categoryIds);

            // Send confirmation email to authenticated user
            await createDonationTask;

            if (!createDonationTask.IsCompletedSuccessfully)
            {
                return(RedirectToAction(nameof(Home.Index), nameof(Home)));
            }
            if (User.Identity.IsAuthenticated)
            {
                _ = _emailService.SendDonationConfirmation(donation);
            }
            return(View());
        }
Example #17
0
        public async Task <IActionResult> Donate(DonateViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }
            var user   = this.User.Identity.Name;
            var result = await this.service.MakeDonation(model.ProjectId, user, model.Message, model.Amount);

            if (result)
            {
                this.TempData[ProjectConst.TempDataDonated] = string.Format(ProjectConst.SuccessfullyDonated, model.Amount);
                return(this.RedirectToAction(nameof(Details), new { projectId = model.ProjectId }));
            }
            else
            {
                return(this.View(model));
            }
        }
        public async Task <IActionResult> Donate(DonateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var transaction = new Transaction
                {
                    FromAddress        = model.FromAddress,
                    ToAddress          = _db.Foundations.OrderBy(x => x.id).LastOrDefault()?.NameEn,
                    IntendedFoundation = model.ToAddress,
                    Amount             = model.Amount,
                    UnixTimeStamp      = DateTime.Now.ToUnixTimeStamp()
                };

                await _hub.Clients.Group("Donate").SendTransaction(transaction);

                return(Json("Donate Is Pending..."));
            }

            return(RedirectToAction(nameof(Index)));
        }
Example #19
0
        public async Task <Response <string> > Donate(DonateViewModel model)
        {
            var response = new Response <string>();

            try
            {
                var txCount = await _gethClient.Web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(model.Address);

                var encoded = Web3.OfflineTransactionSigner.SignTransaction(model.PrivateKey, model.Campaign, Web3.Convert.ToWei(new BigInteger(model.Amount)), txCount.Value, new BigInteger(40000000000), new BigInteger(400000));
                var txHash  = await _gethClient.Web3.Eth.Transactions.SendRawTransaction.SendRequestAsync("0x" + encoded);

                response.Value     = txHash;
                response.Succeeded = true;
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.Succeeded = false;
            }

            return(response);
        }
        // This method validates model against requirements additional to these set by attributes.
        // If validation fails, add message to ModelState dictionary
        private bool IsModelValid(DonateViewModel model, out List <string> errors)
        {
            errors = new List <string>();
            if (!model.Categories.Any(c => c.IsChecked))
            {
                errors.Add("Musisz zaznaczyć przynajmniej jedną kategorię");
            }

            if (model.PhoneNumber != null)
            {
                if (!IsPhoneNumberValid(model.PhoneNumber))
                {
                    errors.Add("Sprawdź numer telefonu. Dozwolone znaki: 0-9, '+- .'. Przykład: 0048.123 456 789");
                }
            }

            if (!(model.PickUpDateOn > DateTime.Now.AddDays(2)))
            {
                errors.Add("Na zorganizowanie odbioru musimy mieć przynajmniej 3 dni. Wyznacz termin za 3 dni lub późniejszy");
            }
            return(errors.Count == 0);
        }
        public ActionResult Donate(DonateViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (!personRepository.CheckIfUserExists(_userManager.GetUserId(User).ToString()))
            {
                personRepository.AddUser(_userManager.GetUserId(User).ToString());
            }
            string UserId = _userManager.GetUserId(User).ToString();

            donateRepository.Add(new DonateModel()
            {
                DonationId = viewModel.DonationId, FirstName = viewModel.FirstName,
                LastName   = viewModel.LastName, CardNumber = viewModel.CardNumber, Amount = viewModel.Amount, UserId = UserId
            });

            ViewBag.message = "Your donation was successful!";

            return(View(viewModel));
        }
Example #22
0
        public DonateViewModel AddDonation(DonateViewModel item)
        {
            if (item.Description == null)
            {
                item.Description = Constants.CashFinOpDescription;
            }
            var itemToAdd = new Donation
            {
                OrderId      = new Guid(item.OrderId),
                Amount       = item.Amount,
                OrgAccountId = item.BankAccountId,
                CurrencyId   = item.CurrencyId,
                Description  = item.Description,
                UserId       = item.UserId,
                TargetId     = item.TargetId,
                DonatorEmail = item.DonatorEmail,
                DonationDate = Convert.ToDateTime(item.DonationDate)
            };
            var created = _unitOfWork.DonationRepository.Create(itemToAdd);

            _unitOfWork.SaveChanges();
            var result = new DonateViewModel
            {
                Id            = created.Id,
                OrderId       = created.OrderId.ToString(),
                Amount        = created.Amount,
                BankAccountId = created.OrgAccountId,
                CurrencyId    = created.CurrencyId,
                Description   = created.Description,
                UserId        = created.UserId,
                TargetId      = created.TargetId,
                DonatorEmail  = created.DonatorEmail,
                DonationDate  = Convert.ToDateTime(item.DonationDate)
            };

            return(result);
        }
Example #23
0
        public ActionResult Index()
        {
            var model = new DonateViewModel();

            return(View(model));
        }
Example #24
0
 public DonateViewModel AddDonation([FromBody] DonateViewModel item)
 {
     return(_donateMoneyService.AddDonation(item));
 }
        public async Task <IActionResult> GetEstimatedFee(DonateViewModel model)
        {
            var response = await _blockchainService.GetEstimatedFee(model);

            return(Json(response));
        }
 public DonatePage()
 {
     InitializeComponent();
     BindingContext = new DonateViewModel();
 }
        public async Task <IActionResult> Donate(DonateViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;

            System.IO.DirectoryInfo di = new DirectoryInfo(hostingEnv.WebRootPath + "\\dimage\\");

            foreach (FileInfo file in di.GetFiles())
            {
                file.Delete();
            }

            if (_signInManager.IsSignedIn(User))
            {
                var useremail = User.Identity.Name;
                var userdata  = ctx.Users.Where(c => c.Email == useremail).ToList();
                if (userdata != null)
                {
                    var donateData = new Donate
                    {
                        FirstName      = model.FirstName,
                        LastName       = model.LastName,
                        Address        = model.Address,
                        PhoneNumber    = model.PhoneNumber,
                        Email          = model.Email == null ? userdata[0].Email : string.Empty,
                        Amount         = model.Amount,
                        Allocation     = model.Allocation,
                        Item           = model.Item,
                        Quantity       = model.Quantity,
                        ImageUrl       = model.ImageFile,
                        NeedPickup     = model.NeedPickup,
                        CanDropOff     = model.CanDropOff,
                        DatePickDrop   = model.DatePickDrop,
                        DonationType   = model.DonationType,
                        DonationStatus = "pending",
                        UserId         = userdata[0].Id
                    };
                    ctx.Donate.Add(donateData);
                    ctx.SaveChanges();
                    HttpContext.Session.SetString(DonateSession, donateData.Email);
                    HttpContext.Session.SetString("FirstName", donateData.FirstName);
                    HttpContext.Session.SetString("LastName", donateData.LastName);

                    string _MerchantEmail = "*****@*****.**";
                    string _ReturnURL     = "https://*****:*****@gmail.com";
                        string _ReturnURL     = "https://localhost:44396/Account/SuccessfullDonation";
                        string _CancelURL     = "https://localhost:44396/";
                        string _CurrencyCode  = "USD";
                        int    _Amount        = Convert.ToInt32(donateData.Amount);
                        string _ItemName      = "Donate to SecondFamilies"; //We are using this field to pass the order number
                        int    _Discount      = 0;
                        double _Tax           = 0.0;
                        string _PayPalURL     = $"https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business={_MerchantEmail}&return={_ReturnURL}&cancel_return={_CancelURL}&currency_code={_CurrencyCode}&amount={_Amount}&item_name={_ItemName}&discount_amount={_Discount}&tax={_Tax}";

                        Response.Redirect(_PayPalURL);
                    }
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }