示例#1
0
        public ActionResult ChangePassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (BunyStoreDbContext dc = new BunyStoreDbContext())
                {
                    var user = dc.Users.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        user.Password          = Cryptography.CreateMD5(model.NewPassword);
                        user.ResetPasswordCode = "";
                        dc.Configuration.ValidateOnSaveEnabled = false;
                        dc.SaveChanges();
                        message = "Mật khẩu đã thay đổi thành công";
                    }
                }
            }
            else
            {
                message = "Mật khẩu và xác nhận mật khẩu phải giống nhau";
            }
            ViewBag.Message = message;
            return(View(model));
        }
示例#2
0
        public ActionResult SuaThongTin(string emailID)
        {
            string message = "";
            bool   status  = false;

            using (BunyStoreDbContext dc = new BunyStoreDbContext())
            {
                var account = dc.Users.Where(a => a.Email == emailID).FirstOrDefault();
                if (account != null)
                {
                    string resetCode = Guid.NewGuid().ToString();
                    LinkReset(account.Email, resetCode);
                    account.ResetPasswordCode = resetCode;
                    dc.Configuration.ValidateOnSaveEnabled = false;
                    dc.SaveChanges();
                    message = "Đường link đổi mật khẩu đã được gửi vào mail của bạn";
                }
                else
                {
                    message = "Tài khoản không tồn tại";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
示例#3
0
        public ActionResult ThemmoiSp(Product product, FormCollection collection)
        {
            var foodname = collection["Name"];
            var meta     = collection["MetaTitle"];
            var price    = collection["Price"];
            var details  = collection["Detail"];
            var soluong  = collection["Quantity"];
            var anh      = collection["Image"];

            if (string.IsNullOrEmpty(foodname))
            {
                ViewData["Loi"] = "Vui lòng nhập tên món";
            }
            else if (string.IsNullOrEmpty(price.ToString()))
            {
                ViewData["Loi1"] = "vui lòng nhập giá bán";
            }
            else if (string.IsNullOrEmpty(details))
            {
                ViewData["Loi3"] = "Vui lòng nhập chi tiết cho món";
            }
            else if (string.IsNullOrEmpty(soluong))
            {
                ViewData["Loi2"] = "Vui lòng nhập số lượng cho món";
            }
            else if (string.IsNullOrEmpty(anh))
            {
                ViewData["Loi5"] = "Vui lòng chọn ảnh cho món";
            }
            else
            {
                product.Name        = foodname;
                product.Price       = int.Parse(price);
                product.MetaTitle   = meta;
                product.Detail      = details;
                product.Quantity    = int.Parse(soluong);
                product.Image       = anh;
                product.CreatedDate = DateTime.Now;
                db.Products.Add(product);
                db.SaveChanges();
                SetViewBag();
                return(RedirectToAction("Product"));
            }
            return(this.ThemmoiSp());
        }
示例#4
0
        public ActionResult ThemloaiSp(FormCollection collection, ProductCategory productcategory)
        {
            var nametype = collection["Name"];

            if (string.IsNullOrEmpty(nametype))
            {
                ViewData["Loi"] = "Vui lòng nhập tên loại sản phẩm";
            }
            else
            {
                productcategory.Name        = nametype;
                productcategory.CreatedDate = DateTime.Now;
                db.ProductCategories.Add(productcategory);
                db.SaveChanges();
                return(RedirectToAction("ProductCategory"));
            }
            return(this.ThemloaiSp());
        }
        public ActionResult ThemND(FormCollection collection, User user)
        {
            var tennd = collection["Name"];
            var tendn = collection["Username"];
            var pass  = collection["Password"];
            var dc    = collection["Adress"];
            var email = collection["Email"];
            var sdt   = collection["Phone"];

            if (string.IsNullOrEmpty(tendn.ToString()))
            {
                ViewData["Loi1"] = "vui lòng nhập tên đăng nhập";
            }
            else if (string.IsNullOrEmpty(pass))
            {
                ViewData["Loi2"] = "Vui lòng nhập mật khẩu";
            }
            else if (string.IsNullOrEmpty(tennd))
            {
                ViewData["Loi"] = "Vui lòng nhập tên người dùng";
            }
            else if (string.IsNullOrEmpty(email))
            {
                ViewData["Loi5"] = "Vui lòng nhập email";
            }
            else if (string.IsNullOrEmpty(sdt))
            {
                ViewData["Loi6"] = "Vui lòng nhập số điện thoại";
            }
            else
            {
                user.UserName    = tendn;
                user.Password    = pass;
                user.Address     = dc;
                user.Name        = tennd;
                user.Email       = email;
                user.Phone       = sdt;
                user.CreatedDate = DateTime.Now;
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Nguoidung"));
            }
            return(this.ThemND());
        }
示例#6
0
        public ActionResult Themslide(FormCollection collection, Slide slide)
        {
            var nametype = collection["Image"];
            var chitiet  = collection["Description"];

            if (string.IsNullOrEmpty(nametype))
            {
                ViewData["Loi"] = "Vui lòng nhập tên loại sản phẩm";
            }
            else
            {
                slide.Image       = nametype;
                slide.Description = chitiet;
                slide.CreatedDate = DateTime.Now;
                db.Slides.Add(slide);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(this.Themslide());
        }
示例#7
0
 public bool Insert(OrderDetail detail)
 {
     try
     {
         db.OrderDetails.Add(detail);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#8
0
        public JsonResult AccessDeleteFalse(int id)
        {
            Order order = db.Orders.SingleOrDefault(n => n.ID == id);

            ViewBag.ID = order.ID;
            if (order == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            else
            {
                db.Orders.Remove(order);
                db.SaveChanges();
                return(Json(new { status = true }));
            }
        }
示例#9
0
        public ActionResult XuLyMatKhau(int id, string pass, string adress)
        {
            var user        = db.Users.Where(p => p.ID == id).SingleOrDefault();
            var userSession = new UserLogin();

            userSession.UserName    = user.UserName;
            userSession.Password    = pass;
            userSession.Name        = user.Name;
            userSession.Phone       = user.Phone;
            userSession.Email       = user.Email;
            userSession.Address     = adress;
            userSession.CreatedDate = DateTime.Now;
            userSession.UserID      = user.ID;

            user.Address  = adress;
            user.Password = pass;
            db.Users.AddOrUpdate(user);
            db.SaveChanges();

            Session.Add(CommonConstants.USER_SESSION, userSession);
            CommonConstants.loginUser = user;

            return(RedirectToAction("XemThongTin"));
        }
示例#10
0
 public int InsertFeedBack(Feedback fb)
 {
     db.Feedbacks.Add(fb);
     db.SaveChanges();
     return(fb.ID);
 }
示例#11
0
 public long Insert(Order order)
 {
     db.Orders.Add(order);
     db.SaveChanges();
     return(order.ID);
 }
示例#12
0
        //public static Customer temp;
        ////// GET: Paypal



        //tạm tắt
        public ActionResult PaymentWithPaypal(CustomerModel user)
        {
            //getting the apiContext as earlier
            //CustomerModel temp = new CustomerModel();
            //if (user.shipName != null)
            //{
            //    temp.shipName = user.shipName;
            //    temp.Phone = user.Phone;
            //    temp.Email = user.Email;
            //    temp.Address = user.Address;
            //    temp.DistrictID = user.DistrictID;
            //    temp.ProvinceID = user.ProvinceID;
            //    temp.PrecinctID = user.PrecinctID;
            //    CommonConstants.CustomerTemp = temp;
            //}
            APIContext apiContext = PaymentConfiguration.GetAPIContext();

            try
            {
                string payerId = Request.Params["PayerID"];
                if (string.IsNullOrEmpty(payerId))
                {
                    //this section will be executed first because PayerID doesn't exist
                    //it is returned by the create function call of the payment class
                    // Creating a payment
                    // baseURL is the url on which paypal sendsback the data.
                    // So we have provided URL of this controller only
                    string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority
                                     +
                                     "/Payment/PaymentWithPayPal?";
                    //guid we are generating for storing the paymentID received in session
                    //after calling the create function and it is used in the payment execution
                    var guid = Convert.ToString((new Random()).Next(100000));
                    //CreatePayment function gives us the payment approval url
                    //on which payer is redirected for paypal account payment
                    var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid);
                    //get links returned from paypal in response to Create function call
                    var    links             = createdPayment.links.GetEnumerator();
                    string paypalRedirectUrl = null;
                    while (links.MoveNext())
                    {
                        Links lnk = links.Current;
                        if (lnk.rel.ToLower().Trim().Equals("approval_url"))
                        {
                            //saving the payapalredirect URL to which user will be redirected for payment
                            paypalRedirectUrl = lnk.href;
                        }
                    }
                    // saving the paymentID in the key guid
                    Session.Add(guid, createdPayment.id);
                    return(Redirect(paypalRedirectUrl));
                }
                else
                {
                    // This section is executed when we have received all the payments parameters
                    // from the previous call to the function Create
                    // Executing a payment
                    var guid            = Request.Params["guid"];
                    var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string);
                    if (executedPayment.state.ToLower() != "approved")
                    {
                        return(View("FailureView"));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Error" + ex.Message);
                return(View("FailureView"));
            }

            //Khoi tao hoa don
            var order = new KetnoiCSDL.EF.Order();

            //Kiểm tra xem khách hàng có đăng nhập hay không
            var user_temp = (BunyStore.Common.UserLogin)Session[BunyStore.Common.CommonConstants.USER_SESSION];

            if (user_temp != null)
            {
                //Nếu có đăng nhập thì gán vào UserID
                order.CustomerID = user_temp.UserID;
            }

            // tiến hành tạo bill
            order.CreatedDate  = DateTime.Now;
            order.ShipAddress  = Common.CommonConstants.CustomerTemp.Address;
            order.ShipMobile   = Common.CommonConstants.CustomerTemp.Phone;
            order.ShipName     = Common.CommonConstants.CustomerTemp.shipName;
            order.ShipEmail    = Common.CommonConstants.CustomerTemp.Email;
            order.ShipPrecinct = Common.CommonConstants.CustomerTemp.PrecinctID;
            order.ShipProvince = Common.CommonConstants.CustomerTemp.ProvinceID;
            order.ShipDistrict = Common.CommonConstants.CustomerTemp.DistrictID;
            order.Status       = "Chờ xử lý";
            order.PaymentForms = "Paypal";
            try
            {
                var id = new OrderDao().Insert(order);

                var     cart      = (List <CartItem>)Session[CartSession];
                var     detailDao = new KetnoiCSDL.DAO.OrderDetailDao();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    // Tạo mới hóa đơn vào database
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.Product.ID;
                    orderDetail.OrderID   = id;
                    orderDetail.Price     = item.Product.Price;
                    orderDetail.Quantity  = item.Quantity;
                    detailDao.Insert(orderDetail);


                    //cập nhật số lượng bán
                    Product Update_product = db.Products.Where(p => p.ID == item.Product.ID).FirstOrDefault();

                    // chắc chắn rằng không rỗng
                    if (Update_product != null)
                    {
                        //vì trong database set mặc định là null nên không thể cộng được mà phải thêm 1 phần if để kiểm tra null hay có giá trị
                        if (Update_product.BoughtCount == null)
                        {
                            Update_product.BoughtCount = int.Parse(item.Quantity.ToString());
                        }
                        else
                        {
                            Update_product.BoughtCount += item.Quantity;
                        }
                        db.Products.AddOrUpdate(Update_product);
                        db.SaveChanges();
                        var a = Update_product.BoughtCount;
                    }
                    //db.SaveChanges();
                    Session[CartSession] = null;
                }
                Common.CommonConstants.CustomerTemp = null;
            }
            catch (Exception ex)
            {
                //ghi log
                return(Redirect("/loi-thanh-toan"));
            }

            return(RedirectToAction("Success", "Cart"));
        }
示例#13
0
 public long Insert(User entity)
 {
     db.Users.Add(entity);
     db.SaveChanges();
     return(entity.ID);
 }
示例#14
0
 public long Insert(Category category)
 {
     db.Categories.Add(category);
     db.SaveChanges();
     return(category.ID);
 }