Ejemplo n.º 1
0
        public ActionResult CancelTransaction(int id)
        {
            if (Session["UserInfo"] != null)
            {
                var user = Session["UserInfo"] as User;
                using (var context = new GameNepalEntities())
                {
                    var transaction = context.Transactions
                                      .Where(x => x.id.Equals(id) && x.status.Equals((int)TransactionStatus.New) && x.userid.Equals(user.id))
                                      .FirstOrDefault();

                    if (transaction != null)
                    {
                        transaction.status     = (int)TransactionStatus.Cancelled;
                        transaction.updatedate = Helper.GetCurrentDateTime();

                        context.Entry(transaction).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();

                        TempData["CancelErrorMsg"]   = null;
                        TempData["CancelSuccessMsg"] = "<strong>Your order is cancelled successfully.</strong>";
                        return(RedirectToAction("TransactionHistory"));
                    }

                    TempData["CancelErrorMsg"] = "<strong>Some error occured cancelling this order. Please try again.</strong>";
                    return(View("TransactionHistory"));
                }
            }
            return(RedirectToAction("Login", "Home"));
        }
Ejemplo n.º 2
0
        public ActionResult EditProfile(UserViewModel userModel)
        {
            ModelState.Remove("Password");
            TempData["ErrorMsg"] = "";
            if (ModelState.IsValid)
            {
                try
                {
                    using (var context = new GameNepalEntities())
                    {
                        var user = Session["UserInfo"] as User;
                        if (user != null)
                        {
                            var emailExists = context.Users
                                              .Where(x => x.email.Equals(userModel.Email) && !x.id.Equals(user.id))
                                              .FirstOrDefault();

                            if (emailExists != null)
                            {
                                TempData["ErrorMsg"] = "The email address you entered already exists in our system. <br/>Please use a different email address or try Forgot Password from the login page.";
                                return(PartialView("_EditProfile", userModel));
                            }

                            user.type = (int)UserTypes.General;

                            user.updatedate = Helper.GetCurrentDateTime();
                            user.isActive   = true;

                            user.firstname = userModel.FirstName;
                            user.lastname  = userModel.LastName;
                            user.email     = userModel.Email;
                            user.phone     = userModel.Phone;

                            user.gender   = userModel.Gender;
                            user.city     = userModel.City;
                            user.agegroup = userModel.AgeGroup;

                            context.Users.Add(user);
                            context.Entry(user).State = System.Data.Entity.EntityState.Modified;

                            context.SaveChanges();

                            Session["UserInfo"] = user;
                        }
                        TempData["ErrorMsg"] = null;
                        return(Json(new { success = true }));
                    }
                }

                catch
                {
                    TempData["ErrorMsg"] = "<strong>Some unexpected error occured. Please try again!! </strong>";
                    return(PartialView("_EditProfile", userModel));
                }
            }
            else
            {
                return(PartialView("_EditProfile", userModel));
            }
        }
Ejemplo n.º 3
0
        public ActionResult CreateTransaction(TransactionModel transactionModel)
        {
            var user = Session["UserInfo"] as User;

            ViewBag.UserName = user.firstname;

            TempData["ErrorMsg"] = "";
            if (ModelState.IsValid)
            {
                try
                {
                    using (var context = new GameNepalEntities())
                    {
                        var matchingPaymentId = context.Transactions
                                                .Where(x => x.paymentid.Equals(transactionModel.PaymentId) &&
                                                       !x.status.Equals((int)TransactionStatus.Cancelled))
                                                .FirstOrDefault();

                        if (matchingPaymentId != null)
                        {
                            TempData["ErrorMsg"] = "The payment confirmation number already exists in our system.";
                            return(View("Index", transactionModel));
                        }

                        var transaction = new Transaction
                        {
                            createdate = Helper.GetCurrentDateTime(),
                            updatedate = Helper.GetCurrentDateTime(),
                            status     = (int)TransactionStatus.New,
                            userid     = user.id,

                            paypartnerid = transactionModel.PaymentPartnerId,
                            paymentid    = transactionModel.PaymentId,
                            username     = transactionModel.Username,
                            gameid       = transactionModel.GameId,
                            amount       = transactionModel.Amount,
                            remarks      = transactionModel.Remarks
                        };

                        context.Transactions.Add(transaction);
                        context.Entry(transaction).State = System.Data.Entity.EntityState.Added;

                        context.SaveChanges();
                    }
                    TempData["ErrorMsg"]   = null;
                    TempData["SuccessMsg"] = "Your last order is placed successfully. Please <a href='/User/TransactionHistory'> check transaction history.</a>";
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    TempData["ErrorMsg"] = "<strong>Some unexpected error occured. Please try again!! </strong>";
                    return(View("Index", transactionModel));
                }
            }
            else
            {
                return(View("Index", transactionModel));
            }
        }
Ejemplo n.º 4
0
        public ActionResult EditTransaction(TransactionModel transactionModel)
        {
            var user = Session["UserInfo"] as User;

            TempData["ErrorMsg"] = "";
            if (ModelState.IsValid)
            {
                try
                {
                    using (var context = new GameNepalEntities())
                    {
                        var transaction = context.Transactions
                                          .Where(x => x.id.Equals(transactionModel.Id) && x.userid.Equals(user.id))
                                          .FirstOrDefault();

                        var matchingPaymentId = context.Transactions
                                                .Where(x => x.paymentid.Equals(transactionModel.PaymentId) &&
                                                       !x.status.Equals((int)TransactionStatus.Cancelled) &&
                                                       !x.id.Equals(transactionModel.Id))
                                                .FirstOrDefault();

                        if (matchingPaymentId != null)
                        {
                            TempData["ErrorMsg"] = "This payment confirmation number already exists in our system.";
                            return(PartialView("_EditTransaction", transactionModel));
                        }

                        transaction.updatedate = Helper.GetCurrentDateTime();
                        transaction.status     = (int)TransactionStatus.New;
                        transaction.userid     = user.id;

                        transaction.paypartnerid = transactionModel.PaymentPartnerId;
                        transaction.paymentid    = transactionModel.PaymentId;
                        transaction.username     = transactionModel.Username;
                        transaction.gameid       = transactionModel.GameId;
                        transaction.amount       = transactionModel.Amount;
                        transaction.remarks      = transactionModel.Remarks;

                        context.Transactions.Add(transaction);
                        context.Entry(transaction).State = System.Data.Entity.EntityState.Modified;

                        context.SaveChanges();
                    }
                    TempData["ErrorMsg"] = null;
                    return(Json(new { success = true }));
                }

                catch
                {
                    TempData["ErrorMsg"] = "<strong>Some unexpected error occured. Please try again!! </strong>";
                    return(PartialView("_EditTransaction", transactionModel));
                }
            }
            else
            {
                return(PartialView("_EditTransaction", transactionModel));
            }
        }
Ejemplo n.º 5
0
        public ActionResult AddPaymentPartner(PaymentPartnerViewModel model)
        {
            if (Session["UserInfo"] != null)
            {
                TempData["ErrorMsg"] = "";
                if (ModelState.IsValid)
                {
                    try
                    {
                        using (var context = new GameNepalEntities())
                        {
                            var existingAccount = context.PaymentPartners
                                                  .Where(x => x.partnername.Equals(model.PartnerName))
                                                  .FirstOrDefault();

                            if (existingAccount != null)
                            {
                                TempData["ErrorMsg"] = "<strong>This account name already exists in the system.</strong>";
                                return(PartialView("_AddPaymentPartner", model));
                            }

                            var payModel = new PaymentPartner
                            {
                                partnername = model.PartnerName,
                                paymentinfo = model.PaymentInfo,
                                isActive    = true,
                                createdate  = Helper.GetCurrentDateTime(),
                                updatedate  = Helper.GetCurrentDateTime()
                            };

                            context.Entry(payModel).State = System.Data.Entity.EntityState.Added;
                            context.SaveChanges();
                        }
                        TempData["ErrorMsg"] = null;
                        return(Json(new { success = true }));
                    }
                    catch (Exception e)
                    {
                        TempData["ErrorMsg"] = "<strong>Some unexpected error occured. Please try again!! </strong>";
                        return(PartialView("_AddPaymentPartner", model));
                    }
                }
                return(PartialView("_AddPaymentPartner", model));
            }
            return(RedirectToAction("Login", "Home"));
        }
Ejemplo n.º 6
0
        public ActionResult ProcessTransaction(int id, string userAction)
        {
            if (Session["UserInfo"] != null)
            {
                using (var context = new GameNepalEntities())
                {
                    var transaction = context.Transactions
                                      .Where(x => x.id.Equals(id))
                                      .FirstOrDefault();

                    if (transaction != null)
                    {
                        if (userAction == "Cancel" && transaction.status == (int)TransactionStatus.New)
                        {
                            transaction.status = (int)TransactionStatus.Cancelled;
                        }
                        else if (userAction == "Approve" && transaction.status == (int)TransactionStatus.New)
                        {
                            transaction.status = (int)TransactionStatus.Processed;
                        }
                        else if (userAction == "Reset" && transaction.status != (int)TransactionStatus.New)
                        {
                            transaction.status = (int)TransactionStatus.New;
                        }
                        else
                        {
                            return(RedirectToAction("Index"));
                        }

                        transaction.updatedate = Helper.GetCurrentDateTime();

                        context.Entry(transaction).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();

                        TempData["CancelErrorMsg"]   = null;
                        TempData["CancelSuccessMsg"] = "<strong>Order is updated successfully.</strong>";
                        return(RedirectToAction("Index"));
                    }

                    TempData["CancelErrorMsg"] = "<strong>Some error occured performing this operation. Please try again.</strong>";
                    return(RedirectToAction("Index"));
                }
            }
            return(RedirectToAction("Login", "Home"));
        }
Ejemplo n.º 7
0
        public ActionResult UpdatePaymentPartner(int id, string status)
        {
            if (Session["UserInfo"] != null)
            {
                using (var context = new GameNepalEntities())
                {
                    var paymentPartner = context.PaymentPartners
                                         .Where(x => x.id.Equals(id))
                                         .FirstOrDefault();

                    if (paymentPartner != null)
                    {
                        if (status == "Deactivate" && paymentPartner.isActive)
                        {
                            paymentPartner.isActive = false;
                        }

                        else if (status == "Activate" && !paymentPartner.isActive)
                        {
                            paymentPartner.isActive = true;
                        }

                        else
                        {
                            return(RedirectToAction("PaymentPartners"));
                        }

                        paymentPartner.updatedate = Helper.GetCurrentDateTime();

                        context.Entry(paymentPartner).State = System.Data.Entity.EntityState.Modified;
                        context.SaveChanges();

                        TempData["UpdateUserErrorMsg"]   = null;
                        TempData["UpdateUserSuccessMsg"] = "<strong>Payment info is updated successfully.</strong>";
                        return(RedirectToAction("PaymentPartners"));
                    }

                    TempData["UpdateUserErrorMsg"] = "<strong>Some error occured performing this operation. Please try again.</strong>";
                    return(RedirectToAction("PaymentPartners"));
                }
            }
            return(RedirectToAction("Login", "Home"));
        }
Ejemplo n.º 8
0
        public string GenerateToken(int userId)
        {
            try
            {
                using (var context = new GameNepalEntities())
                {
                    var validDate = GetValidPassowrdResetDateTime();

                    var existingToken = context.PasswordTokens
                                        .Where(x => x.userid.Equals(userId) && x.isValid && x.createdate >= validDate)
                                        .FirstOrDefault();

                    if (existingToken == null)
                    {
                        var token    = Guid.NewGuid();
                        var pwdToken = new PasswordToken();

                        pwdToken.createdate = Helper.GetCurrentDateTime();
                        pwdToken.token      = token;
                        pwdToken.userid     = userId;
                        pwdToken.isValid    = true;

                        context.PasswordTokens.Add(pwdToken);
                        context.Entry(pwdToken).State = System.Data.Entity.EntityState.Added;

                        context.SaveChanges();
                        return(token.ToString());
                    }
                    else
                    {
                        return(existingToken.token.ToString());
                    }
                }
            }

            catch (Exception e)
            {
                return("");
            }
        }
Ejemplo n.º 9
0
        public ActionResult Register(UserViewModel userModel)
        {
            var reEnteredPwd = Request.Form["pwdReEntered"].ToString();

            TempData["ErrorMsg"] = "<strong>One or more error occured. </strong>";
            if (ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(reEnteredPwd) || userModel.Password != reEnteredPwd)
                {
                    TempData["ErrorMsg"] = "<strong>Re-entered password does not match. </strong>";
                    return(View("Register", userModel));
                }

                try
                {
                    using (var context = new GameNepalEntities())
                    {
                        var user = new User();

                        var emailExists = context.Users
                                          .Where(x => x.email.Equals(userModel.Email))
                                          .FirstOrDefault();

                        if (emailExists != null)
                        {
                            TempData["ErrorMsg"] = "<strong>The email address you entered already exists in our system. <br/>Please use a different email address or try forgot Passowrd from the login page</strong>";
                            return(View("Register", userModel));
                        }

                        user.type       = (int)UserTypes.General;
                        user.createdate = Helper.GetCurrentDateTime();
                        user.updatedate = Helper.GetCurrentDateTime();
                        user.isActive   = true;

                        user.firstname = userModel.FirstName;
                        user.lastname  = userModel.LastName;
                        user.email     = userModel.Email;
                        user.phone     = userModel.Phone;

                        user.gender   = userModel.Gender;
                        user.city     = userModel.City;
                        user.password = Helper.EncodeToBase64(userModel.Password);
                        user.agegroup = userModel.AgeGroup;

                        context.Users.Add(user);
                        context.Entry(user).State = System.Data.Entity.EntityState.Added;

                        context.SaveChanges();

                        Session["UserInfo"] = user;
                    }
                    TempData["ErrorMsg"] = null;
                    return(RedirectToAction("Index", "User"));
                }

                catch
                {
                    TempData["ErrorMsg"] = "<strong>Some unexpected error occured. Please try again!! </strong>";
                    return(View("Register", userModel));
                }
            }
            else
            {
                return(View("Register", userModel));
            }
        }
Ejemplo n.º 10
0
        public ActionResult ChangePassword(PasswordModel model)
        {
            if (Session["UserInfo"] != null)
            {
                var user = Session["UserInfo"] as User;
                ViewBag.UserName = user.firstname;

                var oldPassword     = Request.Form["oldPassword"].ToString();
                var reEnteredNewPwd = Request.Form["pwdReEntered"].ToString();

                TempData["ErrorMsg"] = "";
                ViewBag.Success      = false;

                if (ModelState.IsValid)
                {
                    if (model.NewPassword != reEnteredNewPwd)
                    {
                        TempData["ErrorMsg"] = "<strong>Re-entered password does not match. </strong>";
                        return(PartialView("_ChangePassword", model));
                    }

                    try
                    {
                        using (var context = new GameNepalEntities())
                        {
                            var hashedOldPwd = Helper.EncodeToBase64(oldPassword);
                            var hashedNewPwd = Helper.EncodeToBase64(model.NewPassword);

                            var contextUser = context.Users.Where(x => x.id.Equals(user.id) &&
                                                                  x.password.Equals(hashedOldPwd) && x.isActive)
                                              .FirstOrDefault();

                            if (contextUser == null)
                            {
                                TempData["ErrorMsg"] = "<strong>Old password does not match. </strong>";
                                return(PartialView("_ChangePassword", model));
                            }

                            else if (contextUser.password.Equals(hashedNewPwd))
                            {
                                TempData["ErrorMsg"] = "<strong>New password should be different from old password. </strong>";
                                return(PartialView("_ChangePassword", model));
                            }

                            else
                            {
                                contextUser.password   = hashedNewPwd;
                                contextUser.updatedate = Helper.GetCurrentDateTime();

                                context.Users.Add(contextUser);
                                context.Entry(contextUser).State = System.Data.Entity.EntityState.Modified;

                                context.SaveChanges();

                                Session["UserInfo"] = contextUser;
                            }
                        }
                        TempData["ErrorMsg"]   = null;
                        TempData["SuccessMsg"] = "Password changed successfully";
                        ViewBag.Success        = true;
                        return(PartialView("_ChangePassword", model));
                    }

                    catch
                    {
                        TempData["ErrorMsg"] = "<strong>Some unexpected error occured. Please try again!! </strong>";
                        return(PartialView("_ChangePassword", model));
                    }
                }
                else
                {
                    return(PartialView("_ChangePassword", model));
                }
            }
            return(RedirectToAction("Login"));
        }
Ejemplo n.º 11
0
        public ActionResult ResetPassword(PasswordModel model)
        {
            if (Session["UserInfo"] != null)
            {
                var user = Session["UserInfo"] as User;

                var reEnteredNewPwd = Request.Form["pwdReEntered"].ToString();

                TempData["ErrorMsg"] = "";
                if (ModelState.IsValid)
                {
                    if (model.NewPassword != reEnteredNewPwd)
                    {
                        TempData["ErrorMsg"] = "<strong>Re-entered password does not match. </strong>";
                        return(View(model));
                    }

                    try
                    {
                        using (var context = new GameNepalEntities())
                        {
                            var hashedNewPwd = Helper.EncodeToBase64(model.NewPassword);

                            var contextUser = context.Users.Where(x => x.id.Equals(user.id) && x.isActive).FirstOrDefault();

                            if (contextUser.password.Equals(hashedNewPwd))
                            {
                                TempData["ErrorMsg"] = "<strong>New password should be different from old password. </strong>";
                                return(RedirectToAction("ResetPassword"));
                            }

                            else
                            {
                                contextUser.password   = hashedNewPwd;
                                contextUser.updatedate = Helper.GetCurrentDateTime();

                                context.Users.Add(contextUser);
                                context.Entry(contextUser).State = System.Data.Entity.EntityState.Modified;

                                var pwdToken = context.PasswordTokens
                                               .Where(x => x.userid.Equals(contextUser.id)).OrderByDescending(x => x.createdate)
                                               .FirstOrDefault();
                                pwdToken.isValid    = false;
                                pwdToken.updatedate = Helper.GetCurrentDateTime();

                                context.PasswordTokens.Add(pwdToken);
                                context.Entry(pwdToken).State = System.Data.Entity.EntityState.Modified;

                                context.SaveChanges();
                                Session["UserInfo"] = contextUser;
                            }
                        }
                        TempData["ErrorMsg"]   = null;
                        TempData["SuccessMsg"] = "Password changed successfully. Please login again!!";
                        return(RedirectToAction("Login"));
                    }

                    catch
                    {
                        TempData["ErrorMsg"] = "Some unexpected error occured. Please try again!! ";
                        return(RedirectToAction("ResetPassword"));
                    }
                }
                else
                {
                    return(View(model));
                }
            }
            return(RedirectToAction("Login"));
        }