Exemplo n.º 1
0
        public ActionResult Delete()
        {
            var entities = new RecipesMVC.Models.EF_DB.RecipesAppEntities();
            var u        = new RecipesMVC.Models.EF_DB.User {
                UserName = User.Identity.Name
            };

            FormsAuthentication.SignOut();
            entities.Users.Attach(u);
            entities.Users.Remove(u);
            entities.SaveChanges();
            entities.Dispose();
            return(Json(new { Message = "SUCCESS" }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public ActionResult DeleteUser(int id)
        {
            var entities = new RecipesMVC.Models.EF_DB.RecipesAppEntities();

            if (entities.Users.Any(u => u.ID == id && !u.Role.Contains("Admin")))
            {
                var u = new RecipesMVC.Models.EF_DB.User {
                    ID = id
                };
                entities.Users.Attach(u);
                entities.Users.Remove(u);
                entities.SaveChanges();
                entities.Dispose();
                return(Json(new { Message = "SUCCESS" }, JsonRequestBehavior.AllowGet));
            }
            entities.Dispose();
            return(Json(new { Message = "ERROR", Error = "UserNotFound" }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
 public ActionResult Change(RecipesMVC.Models.EF_DB.User m)
 {
     if (m.Email != null && m.UserName != null && m.BirthDay.HasValue)
     {
         var entities = new Models.EF_DB.RecipesAppEntities();
         var user     = (from u in entities.Users where u.UserName == User.Identity.Name select u).First();
         user.UserName  = m.UserName;
         user.Email     = m.Email;
         user.BirthDay  = m.BirthDay;
         user.FirstName = m.FirstName;
         entities.SaveChanges();
         entities.Dispose();
         return(Json(new { Message = "SUCCESS" }, JsonRequestBehavior.AllowGet));
     }
     else
     {
         return(Json(new { Message = "Error", Error = "InfoNotFull" }, JsonRequestBehavior.AllowGet));
     }
 }