Example #1
0
        public ActionResult Login(UserViewModel user)
        {
            string          returnUrl = TempData["ReturnUrl"].ToString();
            Tbl_InterimBill ib        = (Tbl_InterimBill)TempData["Cart"];

            if (ModelState.IsValid)
            {
                if (Session["UserName"] != null)
                {
                    string Message = "Index page loaded, Because user already logined.";
                    log.addLog(Message, "Login", "User", logStatus.EventLog);
                    return(RedirectToAction("Index", "Home"));
                }
                var hashedPassword = Crypto.Hash(user.User_Password);
                var user1          = db.Tbl_User.Where(a => a.User_Username == user.User_Username && a.User_Password == hashedPassword).SingleOrDefault();
                if (user1 != null)
                {
                    Session["UserName"] = user1.User_Username;
                    Session["RoleName"] = user1.Tbl_Role.Role_Name;
                    string Message = "User with username " + user1.User_Username + " login successfully.";
                    log.addLog(Message, "Login", "User", logStatus.EventLog);
                    if (returnUrl != null && returnUrl != "")
                    {
                        if (ib != null)
                        {
                            ib.InterimBill_User_ID = user1.User_ID;
                            db.Tbl_InterimBill.Add(ib);
                            db.SaveChanges();
                        }

                        returnUrl = returnUrl.Replace("amp;", "");
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    //نام کاربری اشتباه است
                    string Message = "User with username " + user.User_Username + " login failed. Username or password worng.";
                    log.addLog(Message, "Login", "User", logStatus.EventLog);
                    ViewBag.result        = "نام کاربری و یا کلمه عبور اشتباه است! ";
                    TempData["ReturnUrl"] = returnUrl;
                    TempData["Cart"]      = ib;
                    return(View("Index", user));
                }
            }
            else
            {
                TempData["ReturnUrl"] = returnUrl;
                TempData["Cart"]      = ib;

                return(View("Index"));
            }
        }
Example #2
0
        public ActionResult PaymentVerification(int billID = 0)
        {
            NameValueCollection nvc = Request.Params;
            String Status           = nvc["Status"];

            var bill     = db.Tbl_Bill.Find(billID);
            var user     = db.Tbl_User.Where(a => a.User_ID == bill.Bill_UserID).SingleOrDefault();
            var username = user.User_Username;

            Session["UserName"] = username;

            if (Status != "OK")
            {
                Response.Write("<script>alert('Purchase unsuccessfully')</script>");
                TempData["PayError"] = "متاسفانه پرداخت با موفقیت انجام نشد، لطفا دوباره تلاش کنید.";
                return(RedirectToAction("Index", "Cart"));
            }


            int Amount   = bill.Bill_PayPrice;
            var zarinpal = ZarinPal.ZarinPal.Get();

            zarinpal.DisableSandboxMode();
            //zarinpal.EnableSandboxMode();
            String Authority  = nvc["Authority"];
            String MerchantID = "91afdd4e-006f-11ea-bad7-000c295eb8fc";

            var verificationRequest  = new ZarinPal.PaymentVerification(MerchantID, Amount, Authority);
            var verificationResponse = zarinpal.InvokePaymentVerification(verificationRequest);

            if (verificationResponse.Status == 100)
            {
                //clear carts
                var carts = db.Tbl_UserBills.Where(a => a.UserBills_Bill_ID == bill.Bill_ID).ToList();
                List <Tbl_InterimBill> ib_list = new List <Tbl_InterimBill>();
                foreach (var cart in carts)
                {
                    Tbl_InterimBill ib = new Tbl_InterimBill();
                    ib = db.Tbl_InterimBill.Where(a => a.InterimBill_ID == cart.UserBills_InterimBill_ID).SingleOrDefault();
                    ib.InterimBill_Status = true;
                    db.SaveChanges();
                }
                // db.Tbl_InterimBill.RemoveRange(ib_list);
                //db.SaveChanges();

                //update bill table
                bill.Bill_Status = true;
                //bill.Bill_RefID = RefID;
                db.SaveChanges();

                ViewBag.NameFamily = user.User_NameFamily;
                ViewBag.InvoiceNum = bill.Bill_InvoiceNumber;

                return(View());
            }
            else
            {
                TempData["PayError"] = "تراکنش با موفقیت انجام نشد، لطفا دوباره تلاش کنید.";
                return(RedirectToAction("Index", "Cart"));
            }
        }
Example #3
0
        public JsonResult AddToCart(int PerfumeID = 0, string Category_Title = "", float Weight = 0, int Count = 0)
        {
            String Message = "";

            if (Category_Title == "")
            {
                Message = "added perfume with perfume ID " + PerfumeID + "failed";
                log.addLog(Message, "AddToCart", "Cart", logStatus.EventLog);
                string message = "محصول به سبد اضافه نشد، لطفا اطلاعات محصول را با دقت وارد نمایید.";
                return(Json(message, JsonRequestBehavior.AllowGet));
            }
            else
            {
                try
                {
                    Tbl_InterimBill ib       = new Tbl_InterimBill();
                    var             category = db.Tbl_Category.Where(a => a.Category_Title == Category_Title).SingleOrDefault();
                    ib.InterimBill_Category_ID = category.Category_ID;
                    ib.InterimBill_Weight      = Weight;
                    ib.InterimBill_Count       = Count;
                    ib.InterimBill_Date        = DateTime.Now;
                    ib.InterimBill_ExpDate     = DateTime.Now.AddDays(5);


                    Random rnd1          = new Random();
                    int    InvoiceNumber = (rnd1.Next(1, 1000) * DateTime.Now.Year) + DateTime.Now.Second;
                    ib.InterimBill_InvoiceNum = InvoiceNumber;
                    ib.InterimBill_Perfume_ID = PerfumeID;
                    if (Category_Title == "ادکلن")
                    {
                        var cologne = db.Tbl_Cologne.Where(a => a.Cologne_Perfume_ID == PerfumeID && a.Cologne_Weight == Weight).SingleOrDefault();
                        if (cologne != null)
                        {
                            ib.InterimBill_Price = (cologne.Cologne_PricePerUnit) * Count;
                        }
                        else
                        {
                            ib.InterimBill_Price = 0;
                        }
                        if (Count > cologne.Cologne_AllCount)
                        {
                            string message = "تعداد انتخاب شده بیشتر از موجودی می باشد، لطفا تماس بگیرید.(09128774252)";
                            return(Json(message, JsonRequestBehavior.AllowGet));
                        }
                    }
                    else if (Category_Title == "سمپل شرکتی")
                    {
                        var sample = db.Tbl_CompanySample.Where(a => a.CompanySample_Perfume_ID == PerfumeID && (float)a.CompanySample_Weight == (float)Weight).SingleOrDefault();
                        if (sample != null)
                        {
                            var pricePerUnit = Convert.ToInt32(sample.CompanySample_Price);
                            ib.InterimBill_Price = pricePerUnit * Count;
                        }
                        else
                        {
                            ib.InterimBill_Price = 0;
                        }
                        if (Count > sample.CompanySample_AllCount)
                        {
                            string message = "تعداد انتخاب شده بیشتر از موجودی می باشد، لطفا تماس بگیرید.(09128774252)";
                            return(Json(message, JsonRequestBehavior.AllowGet));
                        }
                    }
                    else
                    {
                        var handy_sample = db.Tbl_HandySample.Where(a => a.HandySample_Perfume_ID == PerfumeID).SingleOrDefault();
                        if (handy_sample != null)
                        {
                            var pricePerMil = Convert.ToInt32(handy_sample.HandySample_PricePerMil * Weight);
                            ib.InterimBill_Price = pricePerMil * Count;
                        }
                        else
                        {
                            ib.InterimBill_Price = 0;
                        }
                        if (Count * Weight > handy_sample.HandySample_AllWeight)
                        {
                            string message = "تعداد انتخاب شده بیشتر از موجودی می باشد، لطفا تماس بگیرید.(09128774252)";
                            return(Json(message, JsonRequestBehavior.AllowGet));
                        }
                    }
                    ib.InterimBill_Status = false;

                    if (Session["UserName"] == null)
                    {
                        Message = "Access denied. need login.";
                        log.addLog(Message, "AddCart", "Cart", logStatus.EventLog);
                        string message = "Login";

                        TempData["Cart"] = ib;
                        return(Json(message, JsonRequestBehavior.AllowGet));
                    }

                    string username = Session["UserName"].ToString();
                    var    userID   = db.Tbl_User.Where(a => a.User_Username == username).SingleOrDefault().User_ID;
                    ib.InterimBill_User_ID = userID;

                    db.Tbl_InterimBill.Add(ib);
                    if (Convert.ToBoolean(db.SaveChanges() > 0))
                    {
                        Message = "perfume with perfume ID " + PerfumeID + " added to cart successfully.";
                        log.addLog(Message, "AddCart", "Cart", logStatus.EventLog);
                        string message = "OK";
                        return(Json(message, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        Message = "added perfume with perfume ID " + PerfumeID + " failed.";
                        log.addLog(Message, "AddCart", "Cart", logStatus.ErrorLog);
                        string message = "محصول به سبد اضافه نشد، لطفا دوباره تلاش کنید.";
                        return(Json(message, JsonRequestBehavior.AllowGet));
                    }
                }
                catch
                {
                    Message = "added perfume with perfume ID " + PerfumeID + " failed.";
                    log.addLog(Message, "AddCart", "Cart", logStatus.ErrorLog);
                    string message = "محصول به سبد اضافه نشد، لطفا دوباره تلاش کنید.";
                    return(Json(message, JsonRequestBehavior.AllowGet));
                }
            }
        }
Example #4
0
        public ActionResult Register(UserViewModel userViewModel)
        {
            string          returnUrl = TempData["ReturnUrl"].ToString();
            Tbl_InterimBill ib        = (Tbl_InterimBill)TempData["Cart"];

            if (userViewModel.User_Email != null && userViewModel.User_Email != "" &&
                userViewModel.User_Password != null && userViewModel.User_Password != "" &&
                userViewModel.User_Username != null && userViewModel.User_Username != "")
            {
                if (Session["UserName"] != null)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                var existUser = db.Tbl_User.Where(a => a.User_Username == userViewModel.User_Username && a.User_Email == userViewModel.User_Email).SingleOrDefault();
                if (existUser == null)
                {
                    Tbl_User user = new Tbl_User();
                    user.User_Username = userViewModel.User_Username;
                    user.User_Password = userViewModel.User_Password;
                    user.User_Email    = userViewModel.User_Email;

                    user.User_Date    = DateTime.Now;
                    user.User_Active  = true;
                    user.User_Role_ID = 2;

                    user.User_Password = Crypto.Hash(user.User_Password);
                    db.Tbl_User.Add(user);
                    if (Convert.ToBoolean(db.SaveChanges() > 0))
                    {
                        Session["UserName"] = user.User_Username;
                        Session["RoleName"] = "User";
                        String Message = "User with username " + user.User_Username + "registered successfully.";
                        log.addLog(Message, "Register", "Account", logStatus.EventLog);

                        if (returnUrl != null && returnUrl != "")
                        {
                            if (ib != null)
                            {
                                ib.InterimBill_User_ID = user.User_ID;

                                db.Tbl_InterimBill.Add(ib);
                                db.SaveChanges();
                            }
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        String Message = "register User with username " + user.User_Username + "failed.";
                        log.addLog(Message, "Register", "Account", logStatus.ErrorLog);
                        TempData["ReturnUrl"] = returnUrl;
                        TempData["Cart"]      = ib;
                        ViewBag.Register      = true;
                        return(View("Index", userViewModel));
                    }
                }
                else
                {
                    String Message = "register User with username " + userViewModel.User_Username + "failed.";
                    log.addLog(Message, "Register", "Account", logStatus.EventLog);
                    ViewBag.result        = "قبلا با این نام کاربری و ایمیل ثبت نام شده است.";
                    TempData["ReturnUrl"] = returnUrl;
                    TempData["Cart"]      = ib;
                    ViewBag.Register      = true;
                    return(View("Index", userViewModel));
                }
            }
            else
            {
                TempData["ReturnUrl"] = returnUrl;
                TempData["Cart"]      = ib;
                ViewBag.Register      = true;
                ViewBag.result        = "لطفا همه فیلدها را پر کنید.";
                return(View("Index"));
            }
        }