Пример #1
0
 //updates user's data
 public ActionResult Edit(User emp)
 {
     using (LoginDataBaseEntities1 db = new LoginDataBaseEntities1())
     {
         db.Entry(emp).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
Пример #2
0
 // deletes user from database
 public ActionResult Delete(int id)
 {
     using (LoginDataBaseEntities1 db = new LoginDataBaseEntities1())
     {
         User emp = db.Users.Where(x => x.UserID == id).FirstOrDefault <User>();
         db.Users.Remove(emp);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
Пример #3
0
        //adds a new user to database
        public ActionResult Add(User emp)
        {
            using (LoginDataBaseEntities1 db = new LoginDataBaseEntities1())
            {
                emp.Password = Encrypt(emp.Password);

                if (db.Users.Where(x => x.UserName == emp.UserName).FirstOrDefault() == null)
                {
                    db.Users.Add(emp);
                    db.SaveChanges();
                    return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = false, message = "Username already exists" }, JsonRequestBehavior.AllowGet));
                }
            }
        }