public ActionResult Create([Bind(Include = "id,fullname,email,password,user_level,photo")] Adm_User adm_User, HttpPostedFileBase photo)
        {
            if (ModelState.IsValid)
            {
                if (photo == null)
                {
                    Session["uploadError"] = "Your must select your file";
                    return(RedirectToAction("create"));
                }
                if (photo.ContentType != "image/png" && photo.ContentType != "image/jpeg" && photo.ContentType != "image/gif")
                {
                    Session["uploadError"] = "Your file must be jpg,png or gif";
                    return(RedirectToAction("create"));
                }
                if ((photo.ContentLength / 1024) > 1024)
                {
                    Session["uploadError"] = "Your file size must be max 1mb";
                    return(RedirectToAction("create"));
                }
                string filename = DateTime.Now.ToString("ddMMyyyyHHmmssffff") + photo.FileName;
                string path     = Path.Combine(Server.MapPath("~/Uploads"), filename);
                photo.SaveAs(path);
                adm_User.photo = filename;
                db.Adm_User.Add(adm_User);
                adm_User.password = Crypto.HashPassword(adm_User.password);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.user_level = new SelectList(db.UsrLevel, "id", "level_name", adm_User.user_level);
            return(View(adm_User));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Adm_User adm_User = db.Adm_User.Find(id);

            db.Adm_User.Remove(adm_User);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: Back/Adm_User/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Adm_User adm_User = db.Adm_User.Find(id);

            if (adm_User == null)
            {
                return(HttpNotFound());
            }
            return(View(adm_User));
        }
        // GET: Back/Adm_User/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Adm_User adm_User = db.Adm_User.Find(id);

            if (adm_User == null)
            {
                return(HttpNotFound());
            }
            ViewBag.user_level = new SelectList(db.UsrLevel, "id", "level_name", adm_User.user_level);
            return(View(adm_User));
        }
Exemplo n.º 5
0
        public ActionResult Login(Adm_User usr)
        {
            Adm_User enterUser = db.Adm_User.FirstOrDefault(u => u.email == usr.email);

            if (enterUser != null)
            {
                if (Crypto.VerifyHashedPassword(enterUser.password, usr.password))
                {
                    Session["Loginned"]  = true;
                    Session["userId"]    = enterUser.id;
                    Session["userLevel"] = enterUser.user_level;
                    Session["userName"]  = enterUser.fullname;
                    Session["userPhoto"] = enterUser.photo;
                    return(RedirectToAction("index", "dashboard"));
                }
            }
            Session["LoginValid"] = true;
            return(RedirectToAction("index"));
        }
        public ActionResult Edit([Bind(Include = "id,fullname,email,password,user_level,photo")] Adm_User adm_User, HttpPostedFileBase photo)
        {
            if (ModelState.IsValid)
            {
                if (photo != null)
                {
                    if (photo.ContentType != "image/png" && photo.ContentType != "image/jpg" && photo.ContentType != "image/gif" && photo.ContentType != "image/jpeg")
                    {
                        Session["uploadError"] = "your file must be jpg, png, gif, jpeg";
                        return(RedirectToAction("update", "post_galery", new { id = adm_User.id }));
                    }
                    if ((photo.ContentLength / 1024) > 1024)
                    {
                        Session["uploadError"] = "your file size must be max 1mb";
                        return(RedirectToAction("update", "post_galery", new { id = adm_User.id }));
                    }

                    string FileDate = DateTime.Now.ToString("ddMMyyyHHmmssffff") + photo.FileName;
                    string path     = Path.Combine(Server.MapPath("~/Uploads"), FileDate);
                    //string oldpath = Path.Combine(Server.MapPath("~/Uploads"), OldPhoto);
                    //    if (System.IO.File.Exists(oldpath))
                    //    {
                    //        System.IO.File.Delete(oldpath);
                    //    }
                    photo.SaveAs(path);
                    adm_User.photo = FileDate;
                }
                //else
                //{
                //   post_galery.photo = OldPhoto;
                //}
                db.Entry(adm_User).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.user_level = new SelectList(db.UsrLevel, "id", "level_name", adm_User.user_level);
            return(View(adm_User));
        }