public ActionResult Create(User user) { if (Session["LoggedUser"] == null) { return(RedirectToAction("Login", "User")); } // Model Validation if (ModelState.IsValid) { if (user.ImageFile != null) { string fileName = Path.GetFileNameWithoutExtension(user.ImageFile.FileName); string fileExt = Path.GetExtension(user.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + fileExt; user.photo = "~/Images/" + fileName; fileName = Path.Combine(Server.MapPath("~/Images"), fileName); user.ImageFile.SaveAs(fileName); } using (PMEntities context = new PMEntities()) { context.Users.Add(user); context.SaveChanges(); } ViewBag.Message = "Created Successfully"; } else { ViewBag.Error = "Invalid Request"; } return(View()); }
public ActionResult EditProfile(User newdata) { ModelState.Clear(); var loggedUser = (User)Session["LoggedUser"]; using (PMEntities context = new PMEntities()) { if (context.Users.Any(u => u.Id == loggedUser.Id)) { try { User editeduser = context.Users.Find(loggedUser.Id); editeduser.first_name = newdata.first_name; editeduser.last_name = newdata.last_name; editeduser.email = newdata.email; editeduser.jop_description = newdata.jop_description; editeduser.type = editeduser.type; editeduser.password = editeduser.password; editeduser.ConfirmPassword = editeduser.password; editeduser.mobile = newdata.mobile; context.SaveChanges(); return(Json(new { status = "200", data = editeduser, displaySweetAlert = true, message = "User Edited Successfully" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { status = "400", data = " ", displaySweetAlert = true, message = ex.Message }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { status = "404", data = "", message = "User Not found", displaySweetAlert = false }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult DeleteProject(int id) { using (PMEntities context = new PMEntities()) { if (context.projects.Any(p => p.Id == id)) { List <Int32> allowedStatusToDelete = new List <int>(); allowedStatusToDelete.Add(0); allowedStatusToDelete.Add(3); allowedStatusToDelete.Add(4); project pj = context.projects.Find(id); if (allowedStatusToDelete.Contains((int)pj.status)) { context.projects.Remove(pj); context.SaveChanges(); return(Json(new { status = "200", data = 1, displaySweetAlert = true, message = "Project Deleted Successfully" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { status = "444", data = 0, displaySweetAlert = false, message = "You Can't delete this project" }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { status = "404", data = 0, message = "project not found", displaySweetAlert = false }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult AddProject(project newproject) { var loggedUser = (User)Session["LoggedUser"]; using (PMEntities context = new PMEntities()) { int maxPj = context.projects.Count(); if (maxPj > 0) { project last = context.projects.OrderByDescending(p => p.Id).FirstOrDefault(); maxPj = last.Id; } project pj = new project { Id = maxPj + 1, name = newproject.name, status = 0, description = newproject.description, owner_id = loggedUser.Id }; context.projects.Add(pj); context.SaveChanges(); return(Json(new { status = "200", data = pj, displaySweetAlert = true, message = "Project Added Successfully" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult AdminAddProject(project newproject) { using (PMEntities context = new PMEntities()) { int maxPj = context.projects.Count(); if (maxPj > 0) { project last = context.projects.OrderByDescending(p => p.Id).FirstOrDefault(); maxPj = last.Id; } project pj = new project { Id = maxPj + 1, name = newproject.name, status = 0, description = newproject.description, owner_id = newproject.owner_id }; context.projects.Add(pj); context.SaveChanges(); var users = context.Users.Where(u => u.type == "customer").ToList(); ViewBag.users = users; ViewBag.Message = "Project Created Successfully"; return(View()); } }
public ActionResult AddProjectWorker(Team team) { using (PMEntities context = new PMEntities()) { context.Teams.Add(team); context.SaveChanges(); return(Json(new { delteam = team, status = "200", data = 1, message = "project not found", displaySweetAlert = true }, JsonRequestBehavior.AllowGet)); } }
public ActionResult ChangeStatus(project editData) { using (PMEntities context = new PMEntities()) { project pj = context.projects.Find(editData.Id); pj.status = editData.status; context.SaveChanges(); return(Json(new { status = "200", data = pj })); } }
public ActionResult Delete(int id) { using (PMEntities context = new PMEntities()) { var project = context.projects.Single(c => c.Id == id); context.projects.Remove(project); context.SaveChanges(); return(RedirectToAction("PmDashboard", "Home")); } }
public ActionResult ChangeStatusD(int id) { using (PMEntities context = new PMEntities()) { var project = context.projects.Single(c => c.Id == id); project.status = 1; context.SaveChanges(); } return(RedirectToAction("PmDashboard", "Home")); }
public ActionResult SaveComment(pj_manager_request req) { var loggedUser = (User)Session["LoggedUser"]; req.project_manager_id = loggedUser.Id; using (PMEntities context = new PMEntities()) { context.pj_manager_request.Add(req); context.SaveChanges(); } return(RedirectToAction("PmDashboard", "Home")); }
public ActionResult CreateManager(int id, proj_mgr projmgr) { string projDesc = projectInfo.returnProjectDescription(id); if (TryUpdateModel(projmgr)) { _ctx.proj_mgr.Add(projmgr); _ctx.SaveChanges(); return(RedirectToAction("Index", new { searchTerm = projDesc })); } return(View(projmgr)); }
public ActionResult Registration(User user) { try { bool Status = false; string message = ""; // // Model Validation if (ModelState.IsValid) { #region //Email is already Exist var isExist = IsEmailExist(user.email); if (isExist) { ModelState.AddModelError("EmailExist", "Email already exist"); return(View(user)); } #endregion #region to encrypt the password // user.password = Crypto.Hash(user.password); #endregion #region Save to Database using (PMEntities dc = new PMEntities()) { dc.Users.Add(user); dc.SaveChanges(); Status = true; } #endregion Session["LoggedUserID"] = user.Id.ToString(); Session["LoggedUser"] = user; return(RedirectToAction("Index", "Home")); } else { message = "Invalid Request"; } ViewBag.Message = message; ViewBag.Status = Status; } catch (Exception ex) { ViewBag.Message = "Invalid Request"; } return(View(user)); }
public ActionResult Delete(int id) { if (Session["LoggedUser"] == null) { return(RedirectToAction("Login", "User")); } using (PMEntities context = new PMEntities()) { var users = context.Users.FirstOrDefault(u => u.Id == id); context.Users.Remove(users); context.SaveChanges(); } ViewBag.Message = "Deleted Successfully"; return(RedirectToAction("Index")); }
public ActionResult AssignUser(pj_manager_request request) { using (PMEntities context = new PMEntities()) { if (context.projects.Any(p => p.Id == request.project_id)) { project pj = context.projects.Find(request.project_id); pj.project_manager_id = request.project_manager_id; pj.status = 5; context.SaveChanges(); return(Json(new { status = "200", data = request, displaySweetAlert = true, message = "Project Assigned Successfully" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { status = "404", data = "", message = "project not found", displaySweetAlert = false }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult EditProject(project editdata) { using (PMEntities context = new PMEntities()) { if (context.projects.Any(p => p.Id == editdata.Id)) { project pj = context.projects.Find(editdata.Id); pj.name = editdata.name; pj.description = editdata.description; context.SaveChanges(); return(Json(new { status = "200", data = pj, displaySweetAlert = true, message = "Project Edited Successfully" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { status = "404", data = "", message = "project not found", displaySweetAlert = false }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult Edit(User user) { if (Session["LoggedUser"] == null) { return(RedirectToAction("Login", "User")); } // Model Validation if (ModelState.IsValid) { if (user.ImageFile != null) { string fileName = Path.GetFileNameWithoutExtension(user.ImageFile.FileName); string fileExt = Path.GetExtension(user.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + fileExt; user.photo = "~/Images/" + fileName; fileName = Path.Combine(Server.MapPath("~/Images"), fileName); user.ImageFile.SaveAs(fileName); } using (PMEntities context = new PMEntities()) { User updated_user = context.Users.FirstOrDefault(u => u.Id == user.Id); updated_user.first_name = user.first_name; updated_user.last_name = user.last_name; updated_user.jop_description = user.jop_description; updated_user.type = user.type; updated_user.password = user.password; updated_user.ConfirmPassword = user.ConfirmPassword; updated_user.photo = user.photo; updated_user.mobile = user.mobile; updated_user.email = user.email; context.SaveChanges(); ViewBag.Message = "Edit Successfully"; return(View(user)); } } ViewBag.Error = "Invaild Request"; return(View(user)); }
public ActionResult ProfilePhotoHandler() { var loggedUser = (User)Session["LoggedUser"]; if (Request.Files != null) { HttpPostedFileBase file = Request.Files[0]; int fileSize = file.ContentLength; string fileName = file.FileName; string mimeType = file.ContentType; if (mimeType.Contains("image")) { System.IO.Stream fileContent = file.InputStream; string fullFileName = new Random().Next().ToString() + fileName + System.IO.Path.GetExtension(fileName); file.SaveAs(Server.MapPath("~/uploads/") + fullFileName); using (PMEntities context = new PMEntities()) { User editeduser = context.Users.Find(loggedUser.Id); editeduser.photo = fullFileName; editeduser.first_name = editeduser.first_name; editeduser.last_name = editeduser.last_name; editeduser.email = editeduser.email; editeduser.jop_description = editeduser.jop_description; editeduser.type = editeduser.type; editeduser.password = editeduser.password; editeduser.ConfirmPassword = editeduser.password; editeduser.mobile = editeduser.mobile; context.SaveChanges(); } return(Json(new { status = "200", data = fullFileName, displaySweetAlert = true, message = "Photo Uploaded Successfully" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { status = "404", data = "", displaySweetAlert = true, message = "File not allowed" }, JsonRequestBehavior.AllowGet)); } } return(Json(new { status = "404", data = "", displaySweetAlert = true, message = "Retry Again" }, JsonRequestBehavior.AllowGet)); }
// Save public static void Save() { _ctx.SaveChanges(); }