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"); }
// // GET: /Projects/Details/{id} public ActionResult Details(int id) { if (!Auth.IsLoggedIn()) { return RedirectToAction("Login", "Home"); } ProjectContext projectContext = null; using (var db = new DataClassesDataContext()) { Project project = (from p in db.Projects where p.TenantId == Auth.GetCurrentUser().TenantId && p.ProjectId == id select p).FirstOrDefault(); if (project != null) { projectContext = new ProjectContext(project); } } if (projectContext == null) { return View("NotFound"); } return View(projectContext); }
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"); }
public static Project GetProjectById(int id) { Project target = null; using (var db = new DataClassesDataContext()) { target = db.Projects.Where(p => p.TenantId == Auth.GetTenantId() && p.ProjectId == id).FirstOrDefault(); } return target; }
public static List<Project> GetProjects() { List<Project> projects = new List<Project>(); using (var db = new DataClassesDataContext()) { projects = db.Projects.Where(p => p.TenantId == Auth.GetTenantId()).ToList(); } return projects; }
// // GET: /Home/Test public string Test() { DataClassesDataContext db = new DataClassesDataContext(); Tenant test = (from t in db.Tenants where t.TenantId == 1 select t).FirstOrDefault(); db.Dispose(); return test.OrgName; }
public static List<RequirementType> GetCustomTypes() { List<RequirementType> types = new List<RequirementType>(); if (Auth.IsUsingCustomTypes()) { using (var db = new DataClassesDataContext()) { types = db.RequirementTypes.Where(t => t.TenantId == Auth.GetTenantId()).ToList(); } } return types; }
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 static List<SelectListItem> GetManagedProjectSelectItems() { List<SelectListItem> items = new List<SelectListItem>(); using (var db = new DataClassesDataContext()) { var currentUser = Auth.GetCurrentUser(); var projects = db.Projects.Where(p => p.TenantId == currentUser.TenantId && p.ManagerId == currentUser.UserId); foreach (Project project in projects) { items.Add(new SelectListItem { Value = project.ProjectId.ToString(), Text = project.Name }); } } return items; }
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 static List<ProjectContext> GetProjectsByRequirementType(int rTypeId) { List<ProjectContext> projects = new List<ProjectContext>(); using (var db = new DataClassesDataContext()) { var matchedProjects = (from r in db.Requirements join pr in db.ProjectRequirements on r.RequirementId equals pr.RequirementId join p in db.Projects on pr.ProjectId equals p.ProjectId where r.RequirementType.TypeId == rTypeId select p); foreach (Project project in matchedProjects) { projects.Add(new ProjectContext(project)); } } return projects; }
public static CurrentUserContext GetCurrentUser() { CurrentUserContext user = (CurrentUserContext)HttpContext.Current.Session["CurrentUser"]; if (user == null || user.TenantId == null) { return user; } using (var db = new DataClassesDataContext()) { Tenant tenant = (from t in db.Tenants where t.TenantId == user.TenantId select t).FirstOrDefault(); user.LogoPath = tenant.LogoPath; user.TextColor = tenant.TextColor; user.BannerColor = tenant.BannerColor; user.TenantName = tenant.OrgName; user.UsingCustomTypes = tenant.CustomTypes; } return user; }
public static bool Login(LoginContext loginInfo) { bool success = false; if (!string.IsNullOrEmpty(loginInfo.Username) && !string.IsNullOrEmpty(loginInfo.Password)) { using (var db = new DataClassesDataContext()) { User matchedUser = (from u in db.Users where u.Username == loginInfo.Username && u.Password == GetPasswordHash(loginInfo.Password) select u).FirstOrDefault(); if (matchedUser != null) { Login(matchedUser); success = true; } } } return success; }
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(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 static RequirementType GetRequirementTypeById(int id) { RequirementType target = null; using (var db = new DataClassesDataContext()) { target = db.RequirementTypes.Where(t => t.TenantId == Auth.GetTenantId() && t.TypeId == id).FirstOrDefault(); } return target; }
public static List<SelectListItem> GetRequirementTypeSelectItems() { List<SelectListItem> items = new List<SelectListItem>(); using (var db = new DataClassesDataContext()) { var types = db.RequirementTypes.Where(t => t.TenantId == 1 || t.TenantId == Auth.GetCurrentUser().TenantId).OrderBy(t => t.Name); foreach (RequirementType type in types) { items.Add(new SelectListItem { Value = type.TypeId.ToString(), Text = type.Name }); } } return items; }
public static List<SelectListItem> GetRoleSelectItems() { List<SelectListItem> items = new List<SelectListItem>(); using (var db = new DataClassesDataContext()) { var roles = db.Roles.Where(r => r.TenantId == 1 || r.TenantId == Auth.GetCurrentUser().TenantId); foreach (Role role in roles) { items.Add(new SelectListItem { Value = role.RoleId.ToString(), Text = role.Title }); } } return items; }
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 static void Login(User user) { CurrentUserContext currentUser = new CurrentUserContext(); currentUser.TenantId = user.TenantId; currentUser.UserId = user.UserId; currentUser.Username = user.Username; currentUser.IsAdmin = (user.RoleId == 1); currentUser.IsManager = (user.RoleId == 4); using (var db = new DataClassesDataContext()) { Tenant tenant = (from t in db.Tenants where t.TenantId == currentUser.TenantId select t).FirstOrDefault(); currentUser.BannerColor = tenant.BannerColor; currentUser.TextColor = tenant.TextColor; currentUser.TenantName = tenant.OrgName; currentUser.LogoPath = tenant.LogoPath; currentUser.UsingCustomTypes = tenant.CustomTypes; } HttpContext.Current.Session["CurrentUser"] = currentUser; HttpCookie userCookie = new HttpCookie("ProjectManagerUserSession"); userCookie["username"] = user.Username; userCookie["password"] = user.Password; }
// // GET: /Projects/ public ActionResult Index() { if (!Auth.IsLoggedIn()) { return RedirectToAction("Login", "Home"); } //Full project viewing privileges if (Auth.GetCurrentUser().IsAdmin) { List<ProjectContext> projects = new List<ProjectContext>(); using (var db = new DataClassesDataContext()) { var result = (from p in db.Projects where p.TenantId == Auth.GetCurrentUser().TenantId orderby p.ExpectedEnd ascending select p); foreach (var project in result) { projects.Add(new ProjectContext(project)); } } return View(projects); } //Can only view projects they manage else if (Auth.GetCurrentUser().IsManager) { List<ProjectContext> projects = new List<ProjectContext>(); using (var db = new DataClassesDataContext()) { var result = (from p in db.Projects where p.TenantId == Auth.GetCurrentUser().TenantId && p.ManagerId == Auth.GetCurrentUser().UserId orderby p.ExpectedEnd ascending select p); foreach (var project in result) { projects.Add(new ProjectContext(project)); } } return View(projects); } else // employees just view their assigned requirements, not list of projects return RedirectToAction("Index", "Requirements"); }
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 Requirement GetRequirementById(int id) { Requirement target = null; using (var db = new DataClassesDataContext()) { target = db.Requirements.Where(r => r.TenantId == Auth.GetTenantId() && r.RequirementId == id).FirstOrDefault(); } return target; }
public static List<Status> GetStatuses() { List<Status> statuses = new List<Status>(); using (var db = new DataClassesDataContext()) { statuses = db.Status.Where(s => s.TenantId == 1 || s.TenantId == Auth.GetTenantId()).ToList(); } return statuses; }
public static List<SelectListItem> GetStatusSelectItems() { List<SelectListItem> items = new List<SelectListItem>(); using (var db = new DataClassesDataContext()) { var statuses = db.Status.Where(s => s.TenantId == 1 || s.TenantId == Auth.GetCurrentUser().TenantId); foreach (Status status in statuses) { items.Add(new SelectListItem { Value = status.StatusId.ToString(), Text = status.Name }); } } return items; }
public static List<SelectListItem> GetUserSelectItems() { List<SelectListItem> items = new List<SelectListItem>(); using (var db = new DataClassesDataContext()) { var users = db.Users.Where(u => u.TenantId == Auth.GetCurrentUser().TenantId && u.RoleId == 5).OrderBy(u => u.Username); foreach (User user in users) { items.Add(new SelectListItem { Value = user.UserId.ToString(), Text = user.Username }); } } return items; }
public ActionResult Index(string Filter) { Filter = Filter.ToLowerInvariant(); if (!Auth.IsLoggedIn()) { return RedirectToAction("Login", "Home"); } //Full project viewing privileges if (Auth.GetCurrentUser().IsAdmin) { List<ProjectContext> projects = new List<ProjectContext>(); using (var db = new DataClassesDataContext()) { var result = (from p in db.Projects where p.TenantId == Auth.GetCurrentUser().TenantId orderby p.ExpectedEnd ascending select p); foreach (var project in result) { //Filter by project name, status, and project manager if (project.Name.ToLowerInvariant().Contains(Filter) || project.Status1.Name.ToLowerInvariant().Contains(Filter) || project.User.Username.ToLowerInvariant().Contains(Filter)) projects.Add(new ProjectContext(project)); } } return View(projects); } //Can only view projects they manage else if (Auth.GetCurrentUser().IsManager) { List<ProjectContext> projects = new List<ProjectContext>(); using (var db = new DataClassesDataContext()) { var result = (from p in db.Projects where p.TenantId == Auth.GetCurrentUser().TenantId && p.ManagerId == Auth.GetCurrentUser().UserId orderby p.ExpectedEnd ascending select p); foreach (var project in result) { if (project.Name.ToLowerInvariant().Contains(Filter) || project.Status1.Name.ToLowerInvariant().Contains(Filter)) projects.Add(new ProjectContext(project)); } } return View(projects); } else //Will be replaced with viewing requirements, once those are available return View("NotFound"); }
// // 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 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 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; }