public ActionResult Create(Project newProject) { Project project = new Project(); project.TenantId = Auth.GetCurrentUser().TenantId; project.ManagerId = Auth.GetCurrentUser().UserId; project.Name = (!string.IsNullOrWhiteSpace(newProject.Name)) ? newProject.Name : "(Untitled Project)"; project.Start = (newProject.Start != null) ? newProject.Start : DateTime.Now.Date; project.ExpectedEnd = (newProject.ExpectedEnd != null) ? newProject.ExpectedEnd : DateTime.Now.AddMonths(1); project.Status = 1; //Check if the user put the start date after the end date, and swap if so if (project.Start.Value.CompareTo(project.ExpectedEnd.Value) > 0) { var start = project.Start; project.Start = project.ExpectedEnd; project.ExpectedEnd = start; } using (var db = new DataClassesDataContext()) { db.Projects.InsertOnSubmit(project); db.SubmitChanges(); } return RedirectToAction("Index"); }
public ActionResult Create(RequirementContext newRequirement) { bool success = false; using (var db = new DataClassesDataContext()) { User user = (from u in db.Users where u.TenantId == Auth.GetCurrentUser().TenantId && u.UserId == newRequirement.AssignedUserId select u).FirstOrDefault(); Project project = (from p in db.Projects where p.ProjectId == newRequirement.ProjectId && p.TenantId == Auth.GetCurrentUser().TenantId select p).FirstOrDefault(); if (user != null && project != null) { Requirement requirement = new Requirement(); requirement.Description = !String.IsNullOrWhiteSpace(newRequirement.Description) ? newRequirement.Description : ""; requirement.Status = newRequirement.StatusId != 0 ? newRequirement.StatusId : 1; // Defaults to "Not Started" requirement.User = user; // defaults to current user if none specified requirement.TypeId = newRequirement.TypeId; requirement.Time = newRequirement.Time; requirement.TenantId = Auth.GetCurrentUser().TenantId; db.Requirements.InsertOnSubmit(requirement); ProjectRequirement pr = new ProjectRequirement() { Project = project, Requirement = requirement, TenantId = project.TenantId }; db.ProjectRequirements.InsertOnSubmit(pr); db.SubmitChanges(); success = true; } } if (!success) { return View(); } return RedirectToAction("Index"); }
public ActionResult ChangePass(string oldPass, string newPass, string confirmPass) { if (!Auth.IsLoggedIn()) { return RedirectToAction("Login", "Home"); } if (string.IsNullOrWhiteSpace(oldPass) || string.IsNullOrWhiteSpace(newPass) || string.IsNullOrWhiteSpace(confirmPass)) { return View(); } if (newPass != confirmPass) { return View(); } // attempt to log in with current username and oldpass LoginContext tryLogin = new LoginContext(); tryLogin.Username = Auth.GetCurrentUser().Username; tryLogin.Password = oldPass; if (!Auth.Login(tryLogin)) { // FAILED!!! Need to set error code Debug.WriteLine("You Fail!!!"); //Harsh return View(); } // update newPass in database using (var db = new DataClassesDataContext()) { User user = (from u in db.Users where u.TenantId == Auth.GetCurrentUser().TenantId && u.UserId == Auth.GetCurrentUser().UserId select u).FirstOrDefault(); user.Password = Auth.GetPasswordHash(newPass); db.SubmitChanges(); } return RedirectToAction("Index"); }
public ActionResult ChangeColors(string bannerColor, string textColor) { if (!Auth.IsLoggedIn() || !Auth.GetCurrentUser().IsAdmin) { return RedirectToAction("Login", "Home"); } bool changeBanner = !String.IsNullOrWhiteSpace(bannerColor) && bannerColor != Auth.GetCurrentUser().BannerColor; bool changeText = !String.IsNullOrWhiteSpace(textColor) && bannerColor != Auth.GetCurrentUser().TextColor; if (!changeBanner && !changeText) { return RedirectToAction("Index"); } if (changeBanner && !TenantController.OnlyHexInString(bannerColor)) { return RedirectToAction("Index"); } else if (changeText && !TenantController.OnlyHexInString(textColor)) { return RedirectToAction("Index"); } using (var db = new DataClassesDataContext()) { Tenant tenant = (from t in db.Tenants where t.TenantId == Auth.GetCurrentUser().TenantId select t).FirstOrDefault(); if (changeBanner) tenant.BannerColor = bannerColor; if (changeText) tenant.TextColor = textColor; db.SubmitChanges(); } return RedirectToAction("Index"); }
public ActionResult Create(NewTenantContext newTenant, HttpPostedFileBase file) { if (string.IsNullOrWhiteSpace(newTenant.OrgName) || string.IsNullOrWhiteSpace(newTenant.AdminUsername) || string.IsNullOrWhiteSpace(newTenant.AdminPassword) || string.IsNullOrWhiteSpace(newTenant.ConfirmPassword)) { return View(); } if (newTenant.AdminPassword != newTenant.ConfirmPassword) { return View(); } bool success = false; using (var db = new DataClassesDataContext()) { var numMatched = db.Tenants.Where(t => t.OrgName == newTenant.OrgName).Count(); numMatched += db.Users.Where(u => u.Username == newTenant.AdminUsername).Count(); if (numMatched == 0) { Tenant tenant = new Tenant(); tenant.OrgName = newTenant.OrgName; tenant.LogoPath = "/Logos/logo1.jpg"; tenant.BannerColor = OnlyHexInString(newTenant.BannerColor) ? newTenant.BannerColor : "#357ebd"; tenant.TextColor = OnlyHexInString(newTenant.TextColor) ? newTenant.TextColor : "#FFFFFF"; tenant.CustomTypes = newTenant.CustomTypes; User user = new User(); user.Username = newTenant.AdminUsername; user.Password = Auth.GetPasswordHash(newTenant.AdminPassword); user.RoleId = 1; tenant.Users.Insert(tenant.Users.Count, user); db.Tenants.InsertOnSubmit(tenant); db.SubmitChanges(); if (file != null && file.ContentLength > 0) { // store the file inside ~/Logos/uploads folder. Name it Org Name of the tenant string fileName = string.Format("{0}{1}", tenant.TenantId, Path.GetExtension(file.FileName)); string path = Path.Combine(Server.MapPath("~/Logos"), fileName); file.SaveAs(path); tenant.LogoPath = "/Logos/" + fileName; db.SubmitChanges(); } success = true; Auth.Login(user); } } if (!success) { // need to add error message return RedirectToAction("Create"); } return RedirectToAction("Index", "Admin"); }
public ActionResult EditLogo(HttpPostedFileBase file) { if (!Auth.IsLoggedIn() || !Auth.GetCurrentUser().IsAdmin) { return RedirectToAction("Login", "Home"); } if (file == null || file.ContentLength <= 0) { // No file specified return View(); } // file should replace old one with same name so no update to db necessary // but to avoid having to manually change db and commit, i'll reset it anyway :P using (var db = new DataClassesDataContext()) { Tenant tenant = (from t in db.Tenants where t.TenantId == Auth.GetCurrentUser().TenantId select t).FirstOrDefault(); string fileName = string.Format("{0}{1}", tenant.TenantId, Path.GetExtension(file.FileName)); string path = Path.Combine(Server.MapPath("~/Logos"), fileName); file.SaveAs(path); tenant.LogoPath = "/Logos/" + fileName; db.SubmitChanges(); } return RedirectToAction("Index"); }
// // GET: /Requirements/UpdateStatus/{id} public ActionResult UpdateStatus(int id, int newStatus) { bool success = false; using (var db = new DataClassesDataContext()) { Project project = db.Projects.Where(p => p.TenantId == Auth.GetTenantId() && p.ProjectId == id).FirstOrDefault(); if (project != null) { project.Status = newStatus; db.SubmitChanges(); success = true; } } return Json(new { success = success }, JsonRequestBehavior.AllowGet); }
public ActionResult Edit(ProjectContext projectToModify) { using (var db = new DataClassesDataContext()) { var project = (from p in db.Projects where p.ProjectId == projectToModify.ProjectId select p).FirstOrDefault(); //Check to make sure user actually input values project.Name = (!string.IsNullOrWhiteSpace(projectToModify.Name)) ? projectToModify.Name : "(Untitled Project)"; if (projectToModify.RawDateStart != null && projectToModify.RawDateStart != DateTime.MinValue) project.Start = projectToModify.RawDateStart; if (projectToModify.RawDateEnd != null && projectToModify.RawDateEnd != DateTime.MinValue) project.ExpectedEnd = projectToModify.RawDateEnd; //Check if the start date occurs after the end date, and swap them if so if (project.Start.Value.CompareTo(project.ExpectedEnd.Value) > 0) { var start = project.Start; project.Start = project.ExpectedEnd; project.ExpectedEnd = start; } if (projectToModify.StatusId > 0) project.Status = projectToModify.StatusId; db.SubmitChanges(); } return RedirectToAction("Index"); }
public static bool UpdateRequirementType(RequirementType rType) { bool success = false; using (var db = new DataClassesDataContext()) { var target = db.RequirementTypes.Where(t => t.TenantId == Auth.GetTenantId() && t.TypeId == rType.TypeId).FirstOrDefault(); if (target != null) { target.Name = rType.Name; db.SubmitChanges(); success = true; } } return success; }
public static bool InsertRequirementType(RequirementType rType) { bool success = false; rType.TenantId = Auth.GetTenantId(); using (var db = new DataClassesDataContext()) { db.RequirementTypes.InsertOnSubmit(rType); db.SubmitChanges(); success = true; } return success; }
public ActionResult Create(User newUser) { if (!Auth.IsLoggedIn()) { return RedirectToAction("Login", "Home"); } if (!Auth.GetCurrentUser().IsAdmin) { return RedirectToAction("Index"); } if (string.IsNullOrWhiteSpace(newUser.Username) || string.IsNullOrWhiteSpace(newUser.Password)) { return RedirectToAction("Create"); } using (var db = new DataClassesDataContext()) { var existingUser = (from u in db.Users where u.Username == newUser.Username select u).FirstOrDefault(); if (existingUser == null) { User user = new User(); user.TenantId = Auth.GetCurrentUser().TenantId; user.Username = newUser.Username; user.Password = Auth.GetPasswordHash(newUser.Password); user.RoleId = newUser.RoleId > 0 ? newUser.RoleId : 5; // default to GLOBAL.Employee for now user.Role = (from r in db.Roles where r.RoleId == user.RoleId select r).FirstOrDefault(); db.Users.InsertOnSubmit(user); db.SubmitChanges(); } } return RedirectToAction("Index"); }
public ActionResult Edit(User userToModify) { if (!Auth.IsLoggedIn()) { return RedirectToAction("Login", "Home"); } if (!Auth.GetCurrentUser().IsAdmin) { return RedirectToAction("Index"); } using (var db = new DataClassesDataContext()) { var user = (from u in db.Users where u.UserId == userToModify.UserId select u).FirstOrDefault(); if (userToModify.Username != null) user.Username = userToModify.Username; if (userToModify.RoleId > 0) user.RoleId = userToModify.RoleId; db.SubmitChanges(); } return RedirectToAction("Index"); }
// // GET: /Requirements/UpdateStatus/{id} public ActionResult UpdateStatus(int id, int newStatus) { bool success = false; using (var db = new DataClassesDataContext()) { Requirement req = db.Requirements.Where(r => r.TenantId == Auth.GetCurrentUser().TenantId && r.RequirementId == id).FirstOrDefault(); if (req != null) { req.Status = newStatus; db.SubmitChanges(); success = true; } } return Json(new { success = success }, JsonRequestBehavior.AllowGet); }
public ActionResult Edit(RequirementContext requirementToModify) { using (var db = new DataClassesDataContext()) { var requirement = (from r in db.Requirements where r.RequirementId == requirementToModify.RequirementId select r).FirstOrDefault(); //Check to make sure user actually input values if (!string.IsNullOrWhiteSpace(requirementToModify.Description) && requirement.Description != requirementToModify.Description) requirement.Description = requirementToModify.Description; if (requirement.Time != requirementToModify.Time && requirementToModify.Time != 0) requirement.Time = requirementToModify.Time; if (requirementToModify.AssignedUser != null && requirement.AssignedUser != requirementToModify.AssignedUserId) requirement.AssignedUser = requirementToModify.AssignedUserId; if (requirementToModify.StatusId > 0) requirement.Status = requirementToModify.StatusId; if (requirementToModify.TypeId > 0) requirement.TypeId = requirementToModify.TypeId; // if assigned to different project // remove any it was assigned to and assign to new one. // enforces 1->many relationship between projects and requirements if (requirementToModify.ProjectId != 0 && requirementToModify.ProjectId != requirement.ProjectRequirements.FirstOrDefault().ProjectId) { requirement.ProjectRequirements.Clear(); requirement.ProjectRequirements.Add(new ProjectRequirement() { ProjectId = requirementToModify.ProjectId, Requirement = requirement }); } db.SubmitChanges(); } return RedirectToAction("Index"); }