Пример #1
0
        public async Task <ActionResult> Request(Payment model)
        {
            SAPIResponse _pv = await AppManager.GetPV(AppManager.User.Email);

            if (_pv != null && _pv.data != null)
            {
                AssestsRequest _request = new AssestsRequest();
                _request.UserID      = AppManager.User.ID;
                _request.Assest      = "Seratio Coin";
                _request.Quantity    = model.Quantity;
                _request.CreatedOn   = DateTime.Now;
                _request.Status      = "Pending";
                _request.HasRejected = false;
                _request.HasApproved = false;

                db.AssestsRequests.Add(_request);
                await db.SaveChangesAsync();

                TempData["Notification"] = new Notification("Success", "Your request has been processed successfully");
                return(RedirectToAction("requests"));
            }

            else
            {
                TempData["Notification"] = new Notification("Error", "You need to have your Personal Value Score calculated in order to make a transaction.");
            }

            return(RedirectToAction("request"));
        }
        public async Task <ActionResult> Calculate(Data model)
        {
            if (model.country != null)
            {
                model.email    = AppManager.User.Email;
                model.currency = model.country;

                SAPIResponse _response = await AppManager.CalculatePV(model);

                var _user = await db.Users.FirstOrDefaultAsync(i => i.IsDataActive && i.ID == AppManager.User.ID);

                if (_user != null)
                {
                    _user.PV = (decimal)_response.data.pv;
                    await db.SaveChangesAsync();
                }

                if (_response.status.ToLower() == "success")
                {
                    TempData["Notification"] = new Notification("Success", "Your request for the Personal Value Certificate has been processed successfully.");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    TempData["Notification"] = new Notification("Error", "Your request for the Personal Value Certificate cannot be processed now. Please try again later.");
                    return(View());
                }
            }
            else
            {
                TempData["Notification"] = new Notification("Error", "One or more fields are missing or contains invalid value. Please try again later.");
                return(View(model));
            }
        }
        // GET: PV
        public async Task <ActionResult> Index()
        {
            SAPIResponse _response = await AppManager.GetPV(AppManager.User.Email);

            if (_response != null && _response.data != null)
            {
                ViewBag.User = await db.Users.FirstOrDefaultAsync(u => u.IsDataActive && u.ID == AppManager.User.ID);

                if (ViewBag.User != null)
                {
                    ViewBag.PV = ViewBag.User.PV;
                }

                return(View(_response.data));
            }
            else
            {
                return(View());
            }
        }
        public async Task <ActionResult> Approve(int ID)
        {
            if (ID == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Request _request = await db.Requests.FirstOrDefaultAsync(r => r.ID == ID && r.Status == "Pending" && (r.Recipient == AppManager.User.Email || r.Recipient == AppManager.User.NickName) && r.IsDataActive);

            if (_request != null)
            {
                SAPIResponse _response = await AppManager.GetPV(AppManager.User.Email);

                if (_response.data != null)
                {
                    _request.Status      = "Approved";
                    _request.RespondedOn = DateTime.Now;

                    await db.SaveChangesAsync();

                    string _body = $"Hello {(_request.User.NickName != null ? _request.User.NickName : "@" + _request.User.Username)} ,<br /><br />Greeting of the day!<br /><br /><b>{(AppManager.User.NickName != null ? AppManager.User.NickName : "@" + AppManager.User.Username)} </b> has approved your request for the Personal Value Certificate.<br />Please <a href='http://localhost:55409'>Click Here</a> to view it.";
                    AppManager.SendEmail("Request for your Personal Value Certificate has been approved - Seratio Blockchain", _request.User.Email, _body);

                    TempData["Notification"] = new Notification("Success", "Request has been Approved and your Certificate has been shared successfully.");
                }
                else
                {
                    TempData["Notification"] = new Notification("Error", "Sorry, you do not have a Personal Value Certificate. Please create one before approving this Request.");
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                return(HttpNotFound());
            }
        }
        public async Task <ActionResult> PDF(string email, int id)
        {
            SAPIResponse _result = await AppManager.GetPV(email);

            if (_result.data == null)
            {
                return(HttpNotFound());
            }

            var _request = await db.Requests.FirstOrDefaultAsync(r => r.ID == id);

            ViewBag.User = (await db.Users.FirstOrDefaultAsync(u => u.Email == email));

            ViewBag.Nickname = string.IsNullOrEmpty(ViewBag.User.NickName) ? "@" + ViewBag.User.Username : ViewBag.User.NickName;

            if (_request != null)
            {
                _request.HasDownloaded = true;

                await db.SaveChangesAsync();
            }

            return(View(_result));
        }
Пример #6
0
        public async void Execute(IJobExecutionContext context)
        {
            if (!AppManager.IsPVScoreUpdatorRunning)
            {
                AppManager.IsPVScoreUpdatorRunning = true;

                try
                {
                    using (var db = new DatabaseEntities())
                    {
                        List <User> _users = await db.Users.Where(u => u.IsDataActive).ToListAsync();

                        Random random  = new Random();
                        double _factor = random.NextDouble() * (2 - 0);

                        foreach (User _user in _users)
                        {
                            SAPIResponse _response = await AppManager.GetPV(_user.Email);

                            if (_response.data != null)
                            {
                                if (_user.PV == null)
                                {
                                    _user.PV = (decimal)_response.data.pv;
                                    await db.SaveChangesAsync();
                                }

                                if (ShouldIncrement)
                                {
                                    if ((_response.data.pv + 2) > (double)_user.PV)
                                    {
                                        _user.PV = _user.PV + (decimal)_factor;
                                        _user.PVUpdaterStatus = true;
                                    }
                                    else
                                    {
                                        _user.PV = (decimal)_response.data.pv;
                                        _user.PVUpdaterStatus = null;
                                    }
                                }
                                else
                                {
                                    if ((_response.data.pv - 2) < (double)_user.PV)
                                    {
                                        _user.PV = _user.PV - (decimal)_factor;
                                        _user.PVUpdaterStatus = false;
                                    }
                                    else
                                    {
                                        _user.PV = (decimal)_response.data.pv;
                                        _user.PVUpdaterStatus = null;
                                    }
                                }

                                _user.LastUpdatedOn = DateTime.Now;

                                await db.SaveChangesAsync();
                            }
                        }

                        ShouldIncrement = ShouldIncrement ? false : true;
                    }
                }
                catch (Exception ex)
                {
                    ExceptionHandler.Handle(ex);
                }
                finally
                {
                    AppManager.IsPVScoreUpdatorRunning = false;
                }
            }
        }