Ejemplo n.º 1
0
        public ActionResult UploadFiles()
        {
            var    productid             = Convert.ToInt32(Session["ProducId"].ToString());
            var    result                = "Upload fails";
            string path                  = Server.MapPath("~/Content/images/");
            HttpFileCollectionBase files = Request.Files;

            for (int i = 0; i < files.Count; i++)
            {
                HttpPostedFileBase file = files[i];
                file.SaveAs(path + DateTime.Now.ToString("yyyymmddMMss") + file.FileName);

                try
                {
                    Image image = new Image();
                    image.Link      = DateTime.Now.ToString("yyyymmddMMss") + file.FileName;
                    image.IdProduct = productid;
                    db.Image.Add(image);
                    db.SaveChanges();
                    result = " Đã Upload " + files.Count + "Ảnh";
                }

                catch
                {
                    result = "Upload fails";
                }
            }
            return(Json(result));
        }
        public JsonResult PostEditProduct(ProductModel item)
        {
            // var productid = Convert.ToInt32(Session["ProducId"].ToString());
            var result = false;

            if (ModelState.IsValid)
            {
                var product = (from p in db.Product
                               where p.Id == item.Id
                               select p).FirstOrDefault();

                Product productsave = product;
                productsave.Title   = item.Title;
                productsave.Acreage = item.Acreage;
                productsave.Price   = item.Price;
                productsave.IsLevel = item.Islevel;
                db.SaveChanges();

                result = true;


                // RedirectToAction("ThanhToan", "ThanhToan", new { @Idproduct = _idProduct });
            }

            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 3
0
        public JsonResult DangTin(AddProductModel item)
        {
            var result = false;

            if (ModelState.IsValid)
            {
                //save in Location
                Location location = new Location();
                location.Name = item.addressDetails;
                db.Location.Add(location);
                db.SaveChanges();

                var _idlocation = location.Id;

                // save in Product
                Product product = new Product();
                product.IdLocation    = _idlocation;
                product.IdNeedFor     = item.need;
                product.IdProductType = item.type;
                product.IdStreet      = item.street;
                product.Acreage       = item.acreage;
                product.Phone         = item.phone;
                product.Owner         = item.owner;
                product.Title         = item.title;
                product.Price         = item.price;
                product.CreatedDate   = DateTime.Now;
                product.IsLevel       = item.islevel;
                product.IdNeedFor     = 1;
                db.Product.Add(product);
                db.SaveChanges();

                var _idProduct = product.Id;

                // save in ProductDetail
                ProductDetails productDetails = new ProductDetails();
                productDetails.IdProduct     = _idProduct;
                productDetails.PeopleNum     = item.numberPeople;
                productDetails.PriceElectric = item.priceElectric;
                productDetails.PriceWater    = item.priceWater;
                productDetails.Floor         = item.floor;
                productDetails.Sanitary      = item.wc;
                productDetails.Description   = item.description;
                db.ProductDetails.Add(productDetails);
                db.SaveChanges();

                result = true;
                // RedirectToAction("ThanhToan", "ThanhToan", new { @Idproduct = _idProduct });
            }

            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
        public JsonResult PostThanhToan(DateTime ExpireDate, float TotalPrice, int UserId, int IsLevel, string Image)
        {
            var result   = false;
            var product  = db.Product.OrderByDescending(p => p.Id).FirstOrDefault();
            var product1 = db.Product.OrderBy(p => p.Id).FirstOrDefault();
            var image    = (from i in db.Image
                            where i.IdProduct == product1.Id
                            select i).ToList();
            var user = (from u in db.User
                        where u.Id == UserId
                        select u).FirstOrDefault();

            if (ModelState.IsValid)
            {
                //save in Transaction
                Transaction transaction = new Transaction();
                transaction.CreatedDate = DateTime.Now;
                transaction.ExpireDate  = ExpireDate;
                transaction.TotalPrice  = TotalPrice;
                transaction.IdProduct   = product.Id;
                transaction.IdUser      = UserId;
                db.Transaction.Add(transaction);
                db.SaveChanges();

                // save in product
                Product productsave = product;
                productsave.IsActive = 1;
                productsave.IsLevel  = IsLevel;
                productsave.Image    = Image;
                db.SaveChanges();

                // RedirectToAction("ThanhToan", "ThanhToan", new { @Idproduct = _idProduct });

                // save in image
                foreach (Image item in image)
                {
                    item.IdProduct = product.Id;
                    db.SaveChanges();
                }
                result = true;

                //save User
                User usersave = user;
                usersave.Balance = user.Balance - TotalPrice;
                db.SaveChanges();
            }

            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        public JsonResult ThemUser(AddUserModel item)
        {
            var result = false;

            if (ModelState.IsValid)
            {
                var userByEmail = (from u in db.User
                                   where u.Email == item.txtEmail
                                   select u).FirstOrDefault();
                if (userByEmail != null)
                {
                    result = false;
                }
                else
                {
                    User user = new User();
                    user.Email    = item.txtEmail;
                    user.LoginId  = item.txtUser;
                    user.Password = item.txtPass;
                    user.IsActive = item.level;
                    user.Balance  = 0;

                    db.User.Add(user);
                    db.SaveChanges();

                    result = true;
                }

                // RedirectToAction("ThanhToan", "ThanhToan", new { @Idproduct = _idProduct });
            }

            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 6
0
        public JsonResult PostNapTien(string email, string seri, int balance, int menhgia, int type)
        {
            var result = false;


            if (ModelState.IsValid)
            {
                //save in Transaction
                var user = (from u in db.User
                            where u.Email == email
                            select u).FirstOrDefault();

                var card = (from c in db.Card
                            where c.Seri == seri && c.Type == type && c.menhgia == menhgia
                            select c).FirstOrDefault();

                if (card == null)
                {
                    result = false;
                }
                else
                {
                    //save User
                    User usersave = user;
                    usersave.Balance = user.Balance + menhgia;
                    db.SaveChanges();
                    result = true;
                }
            }

            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 7
0
        public JsonResult Update(string loginId, DateTime dateOfBirth, int phone, string address)

        {
            var User   = Session["Email"].ToString();
            var result = false;

            if (ModelState.IsValid)
            {
                var user = (from u in db.User
                            where u.Email == User
                            select u).FirstOrDefault();

                user.DateOfBirth = dateOfBirth;
                user.LoginId     = loginId;
                user.Phone       = phone;
                user.Address     = address;
                db.SaveChanges();
                result = true;
            }

            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 8
0
        public JsonResult PostThanhToan(DateTime ExpireDate, float TotalPrice, int UserId, int IsLevel, int IdProduct)
        {
            var result  = false;
            var product = db.Product.Where(p => p.Id == IdProduct).FirstOrDefault();

            var user = (from u in db.User
                        where u.Id == UserId
                        select u).FirstOrDefault();

            if (ModelState.IsValid)
            {
                //save in Transaction
                var         transactionbyproductid = db.Transaction.Where(p => p.IdProduct == IdProduct).FirstOrDefault();
                Transaction transaction            = transactionbyproductid;
                transaction.CreatedDate = DateTime.Now;
                transaction.ExpireDate  = ExpireDate;
                transaction.TotalPrice  = TotalPrice;
                transaction.IdProduct   = product.Id;
                transaction.IdUser      = UserId;
                db.SaveChanges();

                // save in product
                Product productsave = product;
                productsave.IsActive = 1;
                productsave.IsLevel  = IsLevel;
                db.SaveChanges();

                // RedirectToAction("ThanhToan", "ThanhToan", new { @Idproduct = _idProduct });
                result = true;

                //save User
                User usersave = user;
                usersave.Balance = user.Balance - TotalPrice;
                db.SaveChanges();
            }

            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 9
0
        public JsonResult LuuTin(string email, double priceluutin, int IdProduct)
        {
            var result = false;

            if (ModelState.IsValid)
            {
                var user = (from u in db.User
                            where u.Email == email
                            select u).FirstOrDefault();
                //save User
                User usersave = user;
                usersave.Balance = user.Balance - priceluutin;
                db.SaveChanges();

                SaveProduct saveProduct = new SaveProduct();
                saveProduct.IdUser    = user.Id;
                saveProduct.IdProduct = IdProduct;
                db.SaveProduct.Add(saveProduct);
                db.SaveChanges();
                result = true;
            }

            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 10
0
        public JsonResult PostEditUser(AddUserModel item)
        {
            var result = false;

            if (ModelState.IsValid)
            {
                var user = (from u in db.User
                            where u.Id == item.userid
                            select u).FirstOrDefault();

                User usersave = user;
                usersave.LoginId  = item.txtUser;
                usersave.Password = item.txtPass;
                usersave.IsActive = item.level;
                db.SaveChanges();

                result = true;


                // RedirectToAction("ThanhToan", "ThanhToan", new { @Idproduct = _idProduct });
            }

            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 11
0
        public JsonResult XoaTin(int ProductId)
        {
            var result = false;

            if (ModelState.IsValid)
            {
                var product = (from p in db.Product
                               where p.Id == ProductId
                               select p).FirstOrDefault();
                db.Product.Remove(product);
                db.SaveChanges();
                result = true;
            }
            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 12
0
        public JsonResult SignUp(User user)
        {
            var result     = false;
            var checkEmail = true;

            if (ModelState.IsValid)
            {
                using (NhaTroEntities db = new NhaTroEntities())
                {
                    var userByEmail = (from u in db.User
                                       where u.Email == user.Email
                                       select u).FirstOrDefault();
                    if (userByEmail != null)
                    {
                        checkEmail = false;
                    }

                    else
                    {
                        try
                        {
                            User users = new User();
                            users.LoginId  = user.LoginId;
                            users.Phone    = user.Phone;
                            users.Email    = user.Email;
                            users.Password = user.Password;
                            db.User.Add(users);
                            db.SaveChanges();
                            result = true;
                        }

                        catch
                        {
                            result = false;
                        }
                    }
                }
            }

            return(Json(new { result, checkEmail }, JsonRequestBehavior.AllowGet));
        }