Ejemplo n.º 1
0
        public ActionResult Create(Mslider mslider, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                file = Request.Files["img"];
                string filename      = file.FileName.ToString();
                string slug          = Mystring.ToSlug(mslider.name.ToString());
                string ExtensionFile = Mystring.GetFileExtension(filename);
                string namefilenew   = slug + "." + ExtensionFile;
                var    path          = Path.Combine(Server.MapPath("~/public/images"), namefilenew);

                file.SaveAs(path);
                mslider.url        = slug;
                mslider.img        = namefilenew;
                mslider.created_at = DateTime.Now;
                mslider.updated_at = DateTime.Now;
                mslider.created_by = int.Parse(Session["Admin_id"].ToString());
                mslider.updated_by = int.Parse(Session["Admin_id"].ToString());
                db.Sliders.Add(mslider);
                db.SaveChanges();
                Message.set_flash("Thêm thành công", "success");
                return(RedirectToAction("Index"));
            }
            Message.set_flash("Thêm thất bại", "danger");
            return(View(mslider));
        }
Ejemplo n.º 2
0
        public ActionResult login(FormCollection fc)
        {
            String Username     = fc["username"];
            string Pass         = Mystring.ToMD5(fc["password"]);
            var    user_account = db.users.Where(m => m.access == 1 && m.status == 1 && (m.username == Username));
            var    pass         = user_account.FirstOrDefault()?.password;

            if (user_account.Count() == 0)
            {
                ViewBag.error = "Tên Đăng Nhập Không Đúng";
            }
            else
            {
                var pass_account = user_account.Where(m => m.access == 1 && m.status == 1 && m.password == Pass).FirstOrDefault();
                if (pass_account == null)
                {
                    ViewBag.error = "Mật Khẩu Không Đúng";
                }
                else
                {
                    var user = user_account.First();
                    Session.Add(CommonConstants.CUSTOMER_SESSION, user);
                    Session["userName11"] = user.fullname;
                    Session["id"]         = user.ID;
                    if (!Response.IsRequestBeingRedirected)
                    {
                        Message.set_flash("Đăng nhập thành công ", "success");
                    }
                    return(Redirect("~/tai-khoan"));
                }
            }

            ViewBag.sess = Session["Admin_id"];
            return(View("Login"));
        }
        public ActionResult Create(Product mbook, HttpPostedFileBase file)
        {
            ViewBag.listCate = db.Categorys.Where(m => m.status != 0 && m.ID > 2).ToList();
            if (ModelState.IsValid)
            {
                string slug = Mystring.ToSlug(mbook.name.ToString());
                if (db.Categorys.Where(m => m.slug == slug).Count() > 0)
                {
                    Message.set_flash("Sản phẩm đã tồn tại trong bảng Category", "danger");
                    return(View(mbook));
                }

                if (db.Products.Where(m => m.slug == slug).Count() > 0)
                {
                    Message.set_flash(" Sản phẩm đã tồn tại trong bảng book", "danger");
                    return(View(mbook));
                }
                // lấy tên loại sản phẩm
                var    namecateDb = db.Categorys.Where(m => m.ID == mbook.catid).First();
                string namecate   = Mystring.ToStringNospace(namecateDb.name);
                // lấy tên ảnh
                file = Request.Files["img"];
                string filename = file.FileName.ToString();
                //lấy đuôi ảnh
                string ExtensionFile = Mystring.GetFileExtension(filename);
                // lấy tên sản phẩm làm slug

                //lấy tên mới của ảnh slug + [đuôi ảnh lấy đc]
                string namefilenew = namecate + "/" + slug + "." + ExtensionFile;
                //lưu ảnh vào đường đẫn
                var path = Path.Combine(Server.MapPath("~/public/images/product"), namefilenew);
                //nếu thư mục k tồn tại thì tạo thư mục
                var folder = Server.MapPath("~/public/images/product/" + namecate);
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                file.SaveAs(path);
                mbook.img  = namefilenew;
                mbook.slug = slug;

                mbook.created_at = DateTime.Now;
                mbook.created_by = int.Parse(Session["Admin_id"].ToString());
                db.Products.Add(mbook);
                db.SaveChanges();
                //create Link
                link tt_link = new link();
                tt_link.slug     = slug;
                tt_link.tableId  = 1;
                tt_link.type     = "ProductDetail";
                tt_link.parentId = mbook.ID;
                db.Link.Add(tt_link);
                db.SaveChanges();

                Message.set_flash("Thêm thành công", "success");
                return(RedirectToAction("index"));
            }
            Message.set_flash("Thêm Thất Bại", "danger");
            return(View(mbook));
        }
 public ActionResult Edit(Mproduct mproduct, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         string slug = Mystring.ToSlug(mproduct.name.ToString());
         file = Request.Files["img"];
         string filename = file.FileName.ToString();
         if (filename.Equals("") == false)
         {
             var    namecateDb    = db.Categorys.Where(m => m.ID == mproduct.catid).First();
             string namecate      = Mystring.ToStringNospace(namecateDb.name);
             string ExtensionFile = Mystring.GetFileExtension(filename);
             string namefilenew   = namecate + "/" + slug + "." + ExtensionFile;
             var    path          = Path.Combine(Server.MapPath("~/public/images"), namefilenew);
             var    folder        = Server.MapPath("~/public/images/" + namecate);
             if (!Directory.Exists(folder))
             {
                 Directory.CreateDirectory(folder);
             }
             file.SaveAs(path);
             mproduct.img = namefilenew;
         }
         mproduct.slug            = slug;
         mproduct.updated_at      = DateTime.Now;
         mproduct.updated_by      = int.Parse(Session["Admin_id"].ToString());
         db.Entry(mproduct).State = EntityState.Modified;
         db.SaveChanges();
         ViewBag.listCate = db.Categorys.Where(m => m.status != 0 && m.ID > 2).ToList();
         Message.set_flash("Sửa thành công", "success");
         return(RedirectToAction("Index"));
     }
     Message.set_flash("Sửa thất bại", "danger");
     ViewBag.listCate = db.Categorys.Where(m => m.status != 0 && m.ID > 2).ToList();
     return(View(mproduct));
 }
        public ActionResult Create(ticket ticket)
        {
            ticket.flightCode = "NB_" + ticket.departure_date;
            ticket.img        = "img";
            ticket.sold       = 0;
            if (ModelState.IsValid)
            {
                HttpPostedFileBase file;
                file = Request.Files["airline"];
                string filename      = file.FileName.ToString();
                string ExtensionFile = Mystring.GetFileExtension(filename);
                string namefilenew   = Mystring.ToSlug(ticket.departure_date.Year.ToString()) + "." + ExtensionFile;
                var    path          = Path.Combine(Server.MapPath("~/Public/images/flight"), namefilenew);
                file.SaveAs(path);
                ticket.airline    = namefilenew;
                ticket.created_at = DateTime.Now;
                ticket.updated_at = DateTime.Now;
                ticket.created_by = int.Parse(Session["Admin_id"].ToString());
                ticket.updated_by = int.Parse(Session["Admin_id"].ToString());
                ticket.priceSale  = ticket.price;

                db.tickets.Add(ticket);
                Message.set_flash("Thêm vé thành công", "success");
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            Message.set_flash("Thêm vé thất bại", "danger");
            return(View("Create"));
        }
Ejemplo n.º 6
0
        public ActionResult Login(FormCollection field)
        {
            string    strerror = "";
            string    username = field["email"];
            string    password = Mystring.ToMD5(field["pass"]);
            ModelUser rowuser  = db.Users.Where(m => m.Status == 1 && (m.Phone == username || m.Email == username))
                                 .FirstOrDefault();

            if (rowuser == null)
            {
                strerror = "Tên đăng nhập không tồn tại!";
            }
            else
            {
                if (rowuser.PassWord.Equals(password))
                {
                    Session["UserCustomer"] = rowuser.UserName;
                    Session["UserId"]       = rowuser.Id;
                    Session["FullName"]     = rowuser.FullName;
                    Session["Img"]          = rowuser.Img;
                    Session["Email"]        = rowuser.Email;
                    Session["Phone"]        = rowuser.Phone;
                    return(RedirectToAction("Index", "Site"));
                }
                else
                {
                    strerror = "Mật khẩu không đúng!";
                }
            }
            ViewBag.Error = "<span class='text-danger'>" + strerror + "</span>";
            return(View());
        }
Ejemplo n.º 7
0
 public ActionResult Edit(Mcategory mcategory)
 {
     if (ModelState.IsValid)
     {
         string slug = Mystring.ToSlug(mcategory.name.ToString());
         mcategory.slug            = slug;
         mcategory.updated_at      = DateTime.Now;
         mcategory.updated_by      = int.Parse(Session["Admin_id"].ToString());
         db.Entry(mcategory).State = EntityState.Modified;
         try
         {
             var  thisLink = db.Link.Where(m => m.tableId == 1 && m.parentId == mcategory.ID).First();
             link tt_link  = db.Link.Find(thisLink.ID);
             tt_link.slug            = slug;
             tt_link.tableId         = 1;
             tt_link.parentId        = mcategory.ID;
             db.Entry(tt_link).State = EntityState.Modified;
         }
         catch (Exception)
         {
             //no runing
         }
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     Message.set_flash("Sửa thất bại", "success");
     return(View(mcategory));
 }
Ejemplo n.º 8
0
 public ActionResult Create(Mpost mpost)
 {
     if (ModelState.IsValid)
     {
         HttpPostedFileBase file;
         var    namecateDb = db.topics.Where(m => m.ID == mpost.topid).First();
         string slug       = Mystring.ToSlug(mpost.title.ToString());
         string namecate   = Mystring.ToStringNospace(namecateDb.name);
         file = Request.Files["img"];
         string filename      = file.FileName.ToString();
         string ExtensionFile = Mystring.GetFileExtension(filename);
         string namefilenew   = namecate + "/" + slug + "." + ExtensionFile;
         var    path          = Path.Combine(Server.MapPath("~/public/images/post/"), namefilenew);
         var    folder        = Server.MapPath("~/public/images/" + namecate);
         if (!Directory.Exists(folder))
         {
             Directory.CreateDirectory(folder);
         }
         file.SaveAs(path);
         mpost.img        = namefilenew;
         mpost.slug       = slug;
         mpost.type       = "Post";
         mpost.created_at = DateTime.Now;
         mpost.updated_at = DateTime.Now;
         mpost.created_by = int.Parse(Session["Admin_id"].ToString());
         mpost.updated_by = int.Parse(Session["Admin_id"].ToString());
         db.posts.Add(mpost);
         db.SaveChanges();
         Message.set_flash("Thêm thành công", "success");
         return(RedirectToAction("Index"));
     }
     ViewBag.listTopic = db.topics.Where(m => m.status != 0).ToList();
     Message.set_flash("Thêm Thất Bại", "danger");
     return(View(mpost));
 }
Ejemplo n.º 9
0
        //Adding MyString object in vector
        public void AddStr(char[] strToAdd)
        {
            Array.Resize(ref _text, _text.Length + 1);
            Mystring word = new Mystring(strToAdd);

            _text[_text.Length - 1] = word;
        }
 public ActionResult Create(Muser muser, FormCollection data)
 {
     if (ModelState.IsValid)
     {
         string password1 = data["password1"];
         string password2 = data["password2"];
         string username  = muser.username;
         var    Luser     = db.users.Where(m => m.status == 1 && m.username == username);
         if (password1 != password2)
         {
             ViewBag.error = "PassWord không khớp";
         }
         if (Luser.Count() > 0)
         {
             ViewBag.error1 = "Tên Đăng nhâp đã tồn tại";
         }
         else
         {
             string pass = Mystring.ToMD5(password1);
             muser.img        = "ádasd";
             muser.password   = pass;
             muser.created_at = DateTime.Now;
             muser.updated_at = DateTime.Now;
             muser.created_by = int.Parse(Session["Admin_id"].ToString());
             muser.updated_by = int.Parse(Session["Admin_id"].ToString());
             db.users.Add(muser);
             db.SaveChanges();
             Message.set_flash("Tạo user  thành công", "success");
             return(RedirectToAction("Index"));
         }
     }
     return(View(muser));
 }
Ejemplo n.º 11
0
 public ActionResult Edit(Mslider mslider)
 {
     if (ModelState.IsValid)
     {
         string             slug     = Mystring.ToSlug(mslider.name.ToString());
         HttpPostedFileBase file     = Request.Files["img"];
         string             filename = file.FileName.ToString();
         if (filename.Equals("") == false)
         {
             string ExtensionFile = Mystring.GetFileExtension(filename);
             string namefilenew   = slug + "." + ExtensionFile;
             var    path          = Path.Combine(Server.MapPath("~/public/images"), namefilenew);
             file.SaveAs(path);
             mslider.img = namefilenew;
         }
         mslider.url             = slug;
         mslider.updated_at      = DateTime.Now;
         mslider.updated_by      = int.Parse(Session["Admin_id"].ToString());
         db.Entry(mslider).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.listCate = db.Sliders.Where(m => m.status != 0).ToList();
     return(View(mslider));
 }
Ejemplo n.º 12
0
        public ActionResult login(FormCollection fc)
        {
            string Username = fc["uname"];
            string Pass     = Mystring.ToMD5(fc["psw"]);

            var user_account = db.Users.Where(m => (m.username == Username) && (m.access == 1));

            if (user_account.Count() == 0)
            {
                Message.set_flash("Tên đăng nhập không tồn tại", "danger");
                return(View("login"));
            }
            else
            {
                var pass_account = db.Users.Where(m => m.status == 1 && (m.password == Pass) && (m.access == 1));

                if (pass_account.Count() == 0)
                {
                    Message.set_flash("Mật khẩu không đúng", "danger");
                    return(View("login"));
                }

                else
                {
                    var user = user_account.First();
                    Session.Add(CommonConstants.CUSTOMER_SESSION, user);
                    if (!Response.IsRequestBeingRedirected)
                    {
                        Message.set_flash("Đăng nhập thành công", "success");
                    }
                    return(Redirect("~/"));
                }
            }
        }
Ejemplo n.º 13
0
        public ActionResult Edit(Post post, HttpPostedFileBase file)
        {
            file = Request.Files["img"];
            string filename = file.FileName.ToString();

            if (filename.Equals("") == false)
            {
                string getJsonRepons = SendRequest.sendRequestGET(ApiUrl.urlFindTopicById + post.Topid, null);
                Topic  topic         = JsonConvert.DeserializeObject <Topic>(getJsonRepons);
                string slug          = Mystring.ToSlug(post.Title.ToString()) + DateTime.Now.ToString("-mmss");
                string namecate      = Mystring.ToStringNospace(topic.Name);
                string ExtensionFile = Mystring.GetFileExtension(filename);
                string namefilenew   = namecate + "/" + slug + "." + ExtensionFile;
                var    path          = Path.Combine(Server.MapPath("~/public/images/post"), namefilenew);
                var    folder        = Server.MapPath("~/public/images/post/" + namecate);
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                file.SaveAs(path);
                post.Img = namefilenew;
            }
            post.Updated_at = DateTime.Now;
            JObject PostJson = new JObject
            {
                { "Id", post.ID },
                { "Topid", post.Topid },
                { "Title", post.Title },
                { "Slug", "" },
                { "Detail", post.Detail },
                { "Img", post.Img },
                { "Type", post.Type },
                { "Metakey", post.Metakey },
                { "Metadesc", post.Metadesc },
                { "Created_at", post.Created_at.ToString("yyyy-MM-ddTHH:mm:ss") },
                { "Created_by", post.Created_by },
                { "Updated_at", post.Updated_at.ToString("yyyy-MM-ddTHH:mm:ss") },
                { "Updated_by", post.Updated_by },
                { "Status", post.Status },
            };
            string EditResult   = SendRequest.sendRequestPOSTwithJsonContent(ApiUrl.urlEditPost, PostJson.ToString());
            var    objectResult = JsonConvert.DeserializeObject <ObjectResult <Post> >(EditResult);

            if (objectResult.code == 200)
            {
                Message.set_flash(objectResult.message.Message, "success");
                return(RedirectToAction("index"));
            }
            else
            {
                Message.set_flash(objectResult.message.Message, "danger");
            }
            string getJsonAllTopicRepons = SendRequest.sendRequestGET(ApiUrl.urlGetAllTopic, null);

            ViewBag.listtopic = JsonConvert.DeserializeObject <List <Topic> >(getJsonAllTopicRepons);
            return(View(""));
        }
Ejemplo n.º 14
0
        public ActionResult Signin(ModelUser modelUser)
        {
            string strerror = "";

            if (ModelState.IsValid)
            {
                try
                {
                    var file = Request.Files["img"];
                    if (file == null)
                    {
                        strerror = "Hình Chưa Được Chọn";
                    }
                    else
                    {
                        string[] FileExtentsions = new string[] { ".jpg", ".gif", ".png" };
                        if (!FileExtentsions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
                        {
                            strerror = "Kiểu Tập Tin " + string.Join(", ", FileExtentsions) + " Không Cho Phép!";
                        }
                        else
                        {
                            string strName  = Mystring.str_slug(modelUser.FullName);
                            String fileName = strName + file.FileName.Substring(file.FileName.LastIndexOf('.'));
                            modelUser.Img = fileName;
                            String Strpath = Path.Combine(Server.MapPath("~/Public/Image/User"), fileName);
                            file.SaveAs(Strpath);
                            string matkhau = Mystring.ToMD5(modelUser.PassWord);
                            modelUser.Status     = 1;
                            modelUser.PassWord   = matkhau;
                            modelUser.Created_By = 1;
                            modelUser.Created_At = DateTime.Now;
                            modelUser.Update_By  = 1;
                            modelUser.Update_At  = DateTime.Now;
                            db.Users.Add(modelUser);
                            db.SaveChanges();
                            Session["UserCustomer"] = modelUser.UserName;
                            Session["UserId"]       = modelUser.Id;
                            Session["FullName"]     = modelUser.FullName;
                            Session["Img"]          = modelUser.Img;
                            Session["Email"]        = modelUser.Email;
                            Session["Phone"]        = modelUser.Phone;
                            return(RedirectToAction("Login"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    strerror = "Thêm Không Thành Công";
                }
            }
            ViewBag.Error = strerror;
            return(View(modelUser));
        }
Ejemplo n.º 15
0
        public ActionResult Edit(ModelPost modelPost)
        {
            String baoloi = "";

            if (ModelState.IsValid)
            {
                /* try
                 * {*/
                var file = Request.Files["img"];
                if (file.FileName.Equals(""))
                {
                    string strSlug = Mystring.str_slug(modelPost.Title);
                    modelPost.Slug            = strSlug;
                    modelPost.Update_By       = (int?)Session["UserIdAdmin"];
                    modelPost.Update_At       = DateTime.Now;
                    db.Entry(modelPost).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    string[] FileExtentsions = new string[] { ".jpg", ".gif", ".png" };
                    if (!FileExtentsions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
                    {
                        baoloi += "Kiểu Tập Tin " + string.Join(", ", FileExtentsions) + " Không Cho Phép!";
                    }
                    else
                    {
                        string strSlug  = Mystring.str_slug(modelPost.Title);
                        String fileName = strSlug + file.FileName.Substring(file.FileName.LastIndexOf('.'));
                        modelPost.Img = fileName;
                        String Strpath = Path.Combine(Server.MapPath("~/Public/Image/Product/"), fileName);
                        file.SaveAs(Strpath);
                        modelPost.Slug            = strSlug;
                        modelPost.Update_By       = (int?)Session["UserIdAdmin"];
                        modelPost.Update_At       = DateTime.Now;
                        db.Entry(modelPost).State = EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }

                /*}
                 * catch (Exception ex)
                 * {
                 *  baoloi += "Cập Nhật Không Thành Công";
                 * }*/
            }
            ViewBag.Error = baoloi;
            var listtopid = db.Topic.Where(m => m.Status != 0).ToList();

            ViewBag.ListTopId = new SelectList(listtopid, "Id", "Name", 0);
            return(View(modelPost));
        }
        public ActionResult Edit(ModelUser modelUser)
        {
            String baoloi = "";

            if (ModelState.IsValid)
            {
                try
                {
                    var file = Request.Files["img"];
                    if (!file.FileName.Equals(""))
                    {
                        modelUser.Update_By       = (int?)Session["UserIdAdmin"];
                        modelUser.Update_At       = DateTime.Now;
                        db.Entry(modelUser).State = EntityState.Modified;
                        db.SaveChanges();
                        Session["FullNameAdmin"] = modelUser.FullName;
                        int id = modelUser.Id;
                        Session["UserIdAdmin"] = id;
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        string[] FileExtentsions = new string[] { ".jpg", ".gif", ".png" };
                        if (!FileExtentsions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
                        {
                            baoloi += "Kiểu Tập Tin " + string.Join(", ", FileExtentsions) + " Không Cho Phép!";
                        }
                        else
                        {
                            string strName  = Mystring.str_slug(modelUser.FullName);
                            String fileName = strName + file.FileName.Substring(file.FileName.LastIndexOf('.'));
                            modelUser.Img = fileName;
                            String Strpath = Path.Combine(Server.MapPath("~/Public/Image/User"), fileName);
                            file.SaveAs(Strpath);
                            modelUser.Update_By       = (int?)Session["UserIdAdmin"];
                            modelUser.Update_At       = DateTime.Now;
                            db.Entry(modelUser).State = EntityState.Modified;
                            db.SaveChanges();
                            Session["FullNameAdmin"] = modelUser.FullName;
                            Session["UserIdAdmin"]   = modelUser.Id;
                            Session["ImgAdmin"]      = modelUser.Img;
                            return(RedirectToAction("Index"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    baoloi += "Không Thành Công";
                }
            }
            ViewBag.Error = baoloi;
            return(View(modelUser));
        }
        public ActionResult register(Muser muser, FormCollection fc)
        {
            string uname = fc["uname"];
            string fname = fc["fname"];
            string Pass  = Mystring.ToMD5(fc["psw"]);
            string Pass2 = Mystring.ToMD5(fc["repsw"]);

            if (Pass2 != Pass)
            {
                ViewBag.error = "Mật khẩu không khớp";
                return(View("loginEndRegister"));
            }
            string email   = fc["email"];
            string address = fc["address"];
            string phone   = fc["phone"];

            if (ModelState.IsValid)
            {
                var Luser = db.Users.Where(m => m.status == 1 && m.username == uname && m.access == 1);
                if (Luser.Count() > 0)
                {
                    ViewBag.error = "Tên Đăng Nhập đã tồn tại";
                    return(View("loginEndRegister"));
                }
                else
                {
                    muser.img        = "defalt.png";
                    muser.password   = Pass;
                    muser.username   = uname;
                    muser.fullname   = fname;
                    muser.email      = email;
                    muser.address    = address;
                    muser.phone      = phone;
                    muser.gender     = "nam";
                    muser.access     = 1;
                    muser.created_at = DateTime.Now;
                    muser.updated_at = DateTime.Now;
                    muser.created_by = 1;
                    muser.updated_by = 1;
                    muser.status     = 1;
                    db.Users.Add(muser);
                    db.SaveChanges();
                    Message.set_flash("Đăng ký tài khoản thành công ", "success");
                    return(View("loginEndRegister"));
                }
            }
            Message.set_flash("Đăng ký tài khoản thất bai", "danger");
            return(View("loginEndRegister"));
        }
Ejemplo n.º 18
0
 public ActionResult Edit(Mcategory mcategory)
 {
     if (ModelState.IsValid)
     {
         string slug = Mystring.ToSlug(mcategory.name.ToString());
         mcategory.slug            = slug;
         mcategory.updated_at      = DateTime.Now;
         mcategory.updated_by      = int.Parse(Session["Admin_id"].ToString());
         db.Entry(mcategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     Message.set_flash("Sửa thất bại", "success");
     return(View(mcategory));
 }
Ejemplo n.º 19
0
        public ActionResult Edit(Mtopic mtopic)
        {
            if (ModelState.IsValid)
            {
                string slug = Mystring.ToSlug(mtopic.name.ToString());


                mtopic.updated_at      = DateTime.Now;
                mtopic.updated_by      = int.Parse(Session["Admin_id"].ToString());
                db.Entry(mtopic).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.listtopic = db.topics.Where(m => m.status != 0).ToList();
            return(View(mtopic));
        }
Ejemplo n.º 20
0
        public ActionResult Create(ModelPost modelPost)
        {
            String baoloi = "";

            if (ModelState.IsValid)
            {
                try
                {
                    var file = Request.Files["img"];
                    if (file == null)
                    {
                        ModelState.AddModelError("HINHANH", "Hình Chưa Được Chọn");
                    }
                    else
                    {
                        string[] FileExtentsions = new string[] { ".jpg", ".gif", ".png" };
                        if (!FileExtentsions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
                        {
                            ModelState.AddModelError("HINHANH", "Kiểu Tập Tin " + string.Join(", ", FileExtentsions) + " Không Cho Phép!");
                        }
                        else
                        {
                            string strSlug  = Mystring.str_slug(modelPost.Title);
                            String fileName = strSlug + file.FileName.Substring(file.FileName.LastIndexOf('.'));
                            modelPost.Img = fileName;
                            String Strpath = Path.Combine(Server.MapPath("~/Public/Image/Newspaper/"), fileName);
                            file.SaveAs(Strpath);
                            modelPost.Slug       = strSlug;
                            modelPost.Created_By = (int?)Session["UserIdAdmin"];
                            modelPost.Created_At = DateTime.Now;
                            db.Post.Add(modelPost);
                            db.SaveChanges();
                            return(RedirectToAction("Index"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    baoloi += "Thêm Không Thành Công";
                }
            }
            ViewBag.Error = baoloi;
            var listtopid = db.Topic.Where(m => m.Status != 0).ToList();

            ViewBag.ListTopId = new SelectList(listtopid, "Id", "Name", 0);
            return(View(modelPost));
        }
Ejemplo n.º 21
0
        public async Task <ActionResult> ChangePassWord(Muser muser, FormCollection fc)
        {
            string oldPass      = Mystring.ToMD5(fc["passOld"]);
            string rePass       = Mystring.ToMD5(fc["rePass"]);
            string newPass      = Mystring.ToMD5(fc["password1"]);
            var    pass_account = db.users.Where(m => m.password == oldPass).ToList().Count();

            if (pass_account == 0)
            {
                ViewBag.status = "Mật khẩu không đúng";
                return(View("_changePassword", muser));
            }
            else if (rePass != newPass)
            {
                ViewBag.status = "2 Mật khẩu không khớp";
                return(View("_changePassword", muser));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    var updatedPass = db.users.Find(muser.ID);

                    updatedPass.fullname   = muser.fullname;
                    updatedPass.username   = muser.username;
                    updatedPass.email      = muser.email;
                    updatedPass.phone      = muser.phone;
                    updatedPass.gender     = muser.gender;
                    updatedPass.img        = "bav";
                    updatedPass.password   = newPass;
                    updatedPass.access     = 1;
                    updatedPass.created_at = muser.created_at;
                    updatedPass.updated_at = DateTime.Now;
                    updatedPass.created_by = muser.created_by;
                    updatedPass.updated_by = int.Parse(Session["id"].ToString());
                    updatedPass.status     = 1;

                    db.users.Attach(updatedPass);
                    db.Entry(updatedPass).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    Message.set_flash("Đổi mật khẩu thành công", "success");
                    return(Redirect("~/tai-khoan/" + muser.ID + ""));
                }
            }
            return(View("_changePassword", muser));
        }
        public ActionResult Edit(Product mbook, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                string slug = Mystring.ToSlug(mbook.name.ToString());
                file = Request.Files["img"];
                string filename = file.FileName.ToString();
                if (filename.Equals("") == false)
                {
                    var    namecateDb    = db.Categorys.Where(m => m.ID == mbook.catid).First();
                    string namecate      = Mystring.ToStringNospace(namecateDb.name);
                    string ExtensionFile = Mystring.GetFileExtension(filename);
                    string namefilenew   = namecate + "/" + slug + "." + ExtensionFile;
                    var    path          = Path.Combine(Server.MapPath("~/public/images/product"), namefilenew);
                    var    folder        = Server.MapPath("~/public/images/product/" + namecate);
                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }
                    file.SaveAs(path);
                    mbook.img = namefilenew;
                }
                mbook.slug = slug;
                try
                {
                    var  thisLink = db.Link.Where(m => m.tableId == 1 && m.parentId == mbook.ID).First();
                    link tt_link  = db.Link.Find(thisLink.ID);
                    tt_link.slug            = slug;
                    tt_link.tableId         = 1;
                    tt_link.parentId        = mbook.ID;
                    db.Entry(tt_link).State = EntityState.Modified;
                }
                catch (Exception)
                {
                    //no runing
                }

                db.Entry(mbook).State = EntityState.Modified;
                db.SaveChanges();
                ViewBag.listCate = db.Categorys.Where(m => m.status != 0 && m.ID > 2).ToList();
                Message.set_flash("Sửa thành công", "success");
                return(RedirectToAction("Index"));
            }
            Message.set_flash("Sửa thất bại", "danger");
            ViewBag.listCate = db.Categorys.Where(m => m.status != 0 && m.ID > 2).ToList();
            return(View(mbook));
        }
        public ActionResult login(FormCollection fc)
        {
            String Username     = fc["username"];
            string Pass         = Mystring.ToMD5(fc["password"]);
            var    user_account = db.users.Where(m => m.access != 1 && m.status == 1 && (m.username == Username));
            var    userC        = db.users.Where(m => m.username == Username && m.access == 1);

            if (userC.Count() != 0)
            {
                ViewBag.error = "Bạn không có quyền đăng nhập";
            }
            else
            {
                if (user_account.Count() == 0)
                {
                    ViewBag.error = "Tên Đăng Nhập Không Đúng";
                }
                else
                {
                    var pass_account = db.users.Where(m => m.access != 1 && m.status == 1 && m.password == Pass);
                    if (pass_account.Count() == 0)
                    {
                        ViewBag.error = "Mật Khẩu Không Đúng";
                    }

                    else
                    {
                        var  user        = user_account.First();
                        role role        = db.roles.Where(m => m.parentId == user.access).First();
                        var  userSession = new Userlogin();
                        userSession.UserName   = user.username;
                        userSession.UserID     = user.ID;
                        userSession.GroupID    = role.GropID;
                        userSession.AccessName = role.accessName;
                        Session.Add(CommonConstants.USER_SESSION, userSession);
                        var i = Session["SESSION_CREDENTIALS"];
                        Session["Admin_id"]       = user.ID;
                        Session["Admin_user"]     = user.username;
                        Session["Admin_fullname"] = user.fullname;
                        Response.Redirect("~/Admin");
                    }
                }
            }
            ViewBag.sess = Session["Admin_id"];
            return(View("_login"));
        }
Ejemplo n.º 24
0
        public ActionResult Create(ModelSlider modelSlider)
        {
            string baoloi = "";

            if (ModelState.IsValid)
            {
                try
                {
                    var file = Request.Files["img"];
                    if (file.FileName.Equals(""))
                    {
                        baoloi += "Hình Chưa Được Chọn";
                    }
                    else
                    {
                        string[] FileExtentsions = new string[] { ".jpg", ".gif", ".png" };
                        if (!FileExtentsions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.'))))
                        {
                            baoloi += "Kiểu Tập Tin " + string.Join(", ", FileExtentsions) + " Không Cho Phép!";
                        }
                        else
                        {
                            string strName  = Mystring.str_slug(modelSlider.Name);
                            String fileName = strName + file.FileName.Substring(file.FileName.LastIndexOf('.'));
                            modelSlider.Img = fileName;
                            String Strpath = Path.Combine(Server.MapPath("~/Public/Image/Slider"), fileName);
                            file.SaveAs(Strpath);
                            modelSlider.Created_By = (int?)Session["UserIdAdmin"];
                            modelSlider.Created_At = DateTime.Now;
                            modelSlider.Update_By  = 1;
                            modelSlider.Update_At  = DateTime.Now;
                            db.Slider.Add(modelSlider);
                            db.SaveChanges();
                            return(RedirectToAction("Index"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    baoloi += "Thêm Không Thành Công";
                }
            }
            ViewBag.Error = baoloi;
            return(View(modelSlider));
        }
 public ActionResult Create(topic mtopic)
 {
     if (ModelState.IsValid)
     {
         //category
         string slug = Mystring.ToSlug(mtopic.name.ToString());
         mtopic.slug       = slug;
         mtopic.created_at = DateTime.Now;
         mtopic.updated_at = DateTime.Now;
         mtopic.created_by = int.Parse(Session["Admin_id"].ToString());
         mtopic.updated_by = int.Parse(Session["Admin_id"].ToString());
         db.Topics.Add(mtopic);
         db.SaveChanges();
         Message.set_flash("Thêm thành công", "success");
         return(RedirectToAction("Index"));
     }
     Message.set_flash("Thêm thất bại", "danger");
     ViewBag.listtopic = db.Topics.Where(m => m.status != 0).ToList();
     return(View(mtopic));
 }
        public ActionResult Create(ModelCategories modelCategories)
        {
            ViewBag.ListCat   = new SelectList(db.Categories.Where(m => m.Status != 0).ToList(), "Id", "Name", 0);
            ViewBag.ListOrder = new SelectList(db.Categories.Where(m => m.Status != 0).ToList(), "Orders", "Name", 0);
            String baoloi = "";

            if (ModelState.IsValid)
            {
                try
                {
                    if (modelCategories.ParentId == null)
                    {
                        modelCategories.ParentId = 0;
                    }
                    string slug = Mystring.str_slug(modelCategories.Name);
                    modelCategories.Orders    += 1;
                    modelCategories.Slug       = slug;
                    modelCategories.Created_By = (int?)Session["UserIdAdmin"];
                    modelCategories.Created_At = DateTime.Now;
                    modelCategories.Update_By  = 1;
                    modelCategories.Update_At  = DateTime.Now;
                    db.Categories.Add(modelCategories);
                    //them du lieu bang link
                    ModelLink modelLink = new ModelLink();
                    modelLink.Name    = modelCategories.Name;
                    modelLink.Slug    = modelCategories.Slug;
                    modelLink.TableId = modelCategories.Id;
                    modelLink.Type    = "category";
                    db.Links.Add(modelLink);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    baoloi = "thêm không thành công";
                }
            }
            ViewBag.Error = baoloi;
            return(View(modelCategories));
        }
        public void login(FormCollection fc)
        {
            string Username     = fc["uname"];
            string Pass         = Mystring.ToMD5(fc["psw"]);
            string PassNoMD5    = fc["psw"];
            var    user_account = db.Users.Where(m => (m.username == Username) && (m.access == 1));

            if (user_account.Count() == 0)
            {
                Message.set_flash("Tên đăng nhập không tồn tại", "danger");
                Response.Redirect("~/dang-nhap-dang-ky");
            }
            else
            {
                var pass_account = db.Users.Where(m => m.status == 1 && (m.password == Pass) && (m.access == 1));

                if (pass_account.Count() == 0)
                {
                    Message.set_flash("Mật khẩu không đúng", "danger");
                    Response.Redirect("~/dang-nhap-dang-ky");
                }

                else
                {
                    var user = user_account.First();
                    Session["name"] = user.fullname;
                    Session.Add(CommonConstants.CUSTOMER_SESSION, user);
                    if (!Response.IsRequestBeingRedirected)
                    {
                        Message.set_flash("Đăng nhập thành công", "success");
                    }
                    Response.Redirect("~/thong-tin-kh");
                }
            }
            if (!Response.IsRequestBeingRedirected)
            {
                Response.Redirect("~/");
            }
        }
Ejemplo n.º 28
0
        public JsonResult Edit(Muser muser)
        {
            string new_pass      = Mystring.ToMD5(muser.password);
            var    pass_account  = db.Users.Where(m => m.password == new_pass).ToList().Count();
            var    uname_account = db.Users.Where(m => m.username == muser.username && m.ID != muser.ID).ToList().Count();

            if (pass_account == 0)
            {
                Message.set_flash("Mật khẩu không đúng", "danger");
                return(Json(new { statuss = 1 }, JsonRequestBehavior.AllowGet));
            }
            else if (uname_account > 0)
            {
                Message.set_flash("Tên đăng nhập đã tồn tại", "danger");
                return(Json(new { statuss = 2 }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    Muser muser1 = db.Users.Find(muser.ID);
                    muser.access     = muser1.access;
                    muser.img        = muser1.img;
                    muser.status     = muser1.status;
                    muser.password   = new_pass;
                    muser.created_at = muser1.created_at;
                    muser.updated_at = DateTime.Now;
                    muser.created_by = muser1.created_by;
                    muser.updated_by = muser1.ID;
                    db.Entry(muser1).CurrentValues.SetValues(muser);
                    db.SaveChanges();
                    Session[Common.CommonConstants.CUSTOMER_SESSION] = null;
                    Session.Add(CommonConstants.CUSTOMER_SESSION, muser);
                    Message.set_flash("Cập nhật thành công", "success");
                    return(Json(muser, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(new { statuss = 3 }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 29
0
        public async Task <ActionResult> newPasswordFG(Muser muser, FormCollection fc)
        {
            string rePass  = Mystring.ToMD5(fc["rePass"]);
            string newPass = Mystring.ToMD5(fc["password1"]);

            if (rePass != newPass)
            {
                ViewBag.status = "2 Mật khẩu không khớp";
                return(View("_newPasswordFG", muser));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    var updatedPass = db.users.Find(muser.ID);
                    updatedPass.fullname   = muser.fullname;
                    updatedPass.username   = muser.username;
                    updatedPass.email      = muser.email;
                    updatedPass.phone      = muser.phone;
                    updatedPass.gender     = muser.gender;
                    updatedPass.img        = "bav";
                    updatedPass.password   = newPass;
                    updatedPass.access     = 1;
                    updatedPass.created_at = muser.created_at;
                    updatedPass.updated_at = DateTime.Now;
                    updatedPass.created_by = muser.created_by;
                    updatedPass.updated_by = muser.ID;
                    updatedPass.status     = 1;
                    db.users.Attach(updatedPass);
                    db.Entry(updatedPass).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    Message.set_flash("Reset Mật Khẩu thành công", "success");
                    return(Redirect("~/Trangchu/index"));
                }
            }
            ViewBag.status = "Vui lòng thử lại";
            return(View("_newPasswordFG", muser));
        }
Ejemplo n.º 30
0
 public ActionResult Create(Mcategory mcategory)
 {
     if (ModelState.IsValid)
     {
         //category
         string slug = Mystring.ToSlug(mcategory.name.ToString());
         if (db.Categorys.Where(m => m.slug == slug).Count() > 0)
         {
             Message.set_flash("Loại sản phẩm đã tồn tại trong bảng Category", "danger");
             return(View(mcategory));
         }
         //topic
         if (db.Products.Where(m => m.slug == slug).Count() > 0)
         {
             Message.set_flash("Loại sản phẩm đã tồn tại trong bảng Product", "danger");
             return(View(mcategory));
         }
         mcategory.slug       = slug;
         mcategory.created_at = DateTime.Now;
         mcategory.updated_at = DateTime.Now;
         mcategory.created_by = int.Parse(Session["Admin_id"].ToString());
         mcategory.updated_by = int.Parse(Session["Admin_id"].ToString());
         db.Categorys.Add(mcategory);
         db.SaveChanges();
         //create Link
         link tt_link = new link();
         tt_link.slug     = slug;
         tt_link.tableId  = 2;
         tt_link.type     = "category";
         tt_link.parentId = mcategory.ID;
         db.Link.Add(tt_link);
         db.SaveChanges();
         Message.set_flash("Thêm  thành công", "success");
         return(RedirectToAction("index"));
     }
     Message.set_flash("Thêm  Thất Bại", "danger");
     ViewBag.listCate = db.Categorys.Where(m => m.status != 0).ToList();
     return(View(mcategory));
 }