Exemplo n.º 1
0
        public ActionResult ChangePassword(string CurrentPassword, string NewPassword, string ConfirmPassword)
        {
            using (var context = new AppContextMain())
            {
                User user = context.Users.Find(Convert.ToInt32(Session["UserId"].ToString()));
                if (user.Password != CurrentPassword.Trim())
                {
                    return Json(new { Success = false, Message = "The current password you have entered is incorrect.", Error = 0 }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    if (user.Password == NewPassword.Trim())
                    {
                        return Json(new { Success = false, Message = "New password must be different from current password.", Error = 1 }, JsonRequestBehavior.AllowGet);
                    }
                    else
                    {
                        user.Password = NewPassword.Trim();
                        user.DateUpdated = DateTime.Now;
                        context.Entry(user).State = EntityState.Modified;
                        context.SaveChanges();
                        Session.Clear();
                        Session.Abandon();
                        return Json(new { Success = true, Message = "Password Changed successfully." }, JsonRequestBehavior.AllowGet);
                    }

                }
            }
        }
Exemplo n.º 2
0
 public ActionResult UpdateProfile(User user)
 {
     using (var context = new AppContextMain())
     {
         int userId = Convert.ToInt32(Session["UserId"].ToString());
         if (CheckIfUsernameExists(user.Username.Trim(), userId))
         {
             return Json(new { Success = false, Message = "Username already exists." }, JsonRequestBehavior.AllowGet);
         }
         User temp = context.Users.Find(userId);
         if ((temp.FirstName != user.FirstName.ToLower()) || (temp.LastName != user.LastName.ToLower()) || (temp.Gender != user.Gender) || (temp.BirthDate != user.BirthDate) || (temp.Username != user.Username.Trim()))
         {
             temp.FirstName = user.FirstName.ToLower().Trim();
             temp.LastName = user.LastName.ToLower().Trim();
             temp.Gender = user.Gender;
             temp.BirthDate = user.BirthDate;
             temp.Username = user.Username.Trim();
             temp.DateUpdated = DateTime.Now;
             context.Entry(temp).State = EntityState.Modified;
             context.SaveChanges();
             return Json(new { Success = true, Message = "Profile updated successfully." }, JsonRequestBehavior.AllowGet);
         }
         else
         {
             return Json(new { Success = false }, JsonRequestBehavior.AllowGet);
         }
     }
 }
Exemplo n.º 3
0
 public ActionResult ChangeIsDoneStatus(int?id)
 {
     using (var context = new AppContextMain())
     {
         Todo todo = context.Todos.Find(id);
         todo.IsDone = todo.IsDone == 1 ? 0 : 1;
         context.Entry(todo).State = EntityState.Modified;
         context.SaveChanges();
     }
     return(Json(new { Result = true }, JsonRequestBehavior.AllowGet));
 }
Exemplo n.º 4
0
        public ActionResult Edit(Todo todo)
        {
            if (CheckIfTitleExistsForEdit(todo.Title, todo.TodoId))
            {
                return(Json(new { Result = false, Message = "Title already exists." }, JsonRequestBehavior.AllowGet));
            }

            using (var context = new AppContextMain())
            {
                Todo temp = context.Todos.Find(todo.TodoId);

                if (temp.Title != todo.Title.ToLower() || temp.Description != todo.Description)
                {
                    temp.Title                = todo.Title.ToLower();
                    temp.Description          = todo.Description;
                    temp.DateUpdated          = DateTime.Now;
                    context.Entry(temp).State = EntityState.Modified;
                    context.SaveChanges();
                    return(Json(new { Result = true }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { Result = false }, JsonRequestBehavior.AllowGet));
            }
        }