Ejemplo n.º 1
0
        public void Delete(int id)
        {
            var proj = _rGameDbContext.Categories.FirstOrDefault(x => x.Id == id);

            _rGameDbContext.Entry(proj).State = EntityState.Deleted;
            _rGameDbContext.SaveChanges();
        }
Ejemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "Id,Name")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
Ejemplo n.º 3
0
        public ActionResult Yes(int id)
        {
            GameService service = new GameService(db);
            var         game    = service.GetById(id);

            db.Entry(game).State = EntityState.Modified;
            game.Confirm         = Confirm.Correct.ToString();
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public ActionResult EditUser(User user, HttpPostedFileBase UserPhoto)
        {
            if (UserPhoto != null)
            {
                if (UserPhoto.ContentLength > 1048576)
                {
                    Session["FileSize"] = "File size is a big";
                    RedirectToAction("Edit", "Project", new { id = user.Id });
                }
                if (UserPhoto.ContentType != "image/jpeg" && UserPhoto.ContentType != "image/jpg" && UserPhoto.ContentType != "image/gif" && UserPhoto.ContentType != "image/png")
                {
                    Session["FileSize"] = "Incorrect type";
                    RedirectToAction("Edit", "Project", new { id = user.Id });
                }
                string date     = DateTime.Now.ToString("yyMMddHHmmss");
                string fileName = date + UserPhoto.FileName;
                string path     = Path.Combine(Server.MapPath("~/Uploads/UserImage"), fileName);
                UserPhoto.SaveAs(path);
                user.UserPhoto = fileName;
                User proj = db.Users.Find(user.Id);
                if (proj.UserPhoto != "UserPhoto.png")
                {
                    System.IO.File.Delete(Path.Combine(Server.MapPath("~/Uploads/UserImage"), proj.UserPhoto));
                }

                db.Entry(proj).State = EntityState.Detached;
            }

            if (ModelState.IsValid)
            {
                db.Entry(user).State = EntityState.Modified;
                var userP = Session["User"] as User;
                if (UserPhoto == null)
                {
                    //db.Entry(user).Property(p => p.UserPhoto).IsModified = false;
                    user.UserPhoto = userP.UserPhoto;
                }
                if (user.Password != null)
                {
                    string hashed = Crypto.HashPassword(user.Password);
                    user.Password = hashed;
                }
                user.Role = Role.User.ToString();

                user.Password = userP.Password;


                db.SaveChanges();
                Session["User"] = user;

                return(RedirectToAction("EditUser"));
            }

            return(View(user));
        }