public RequirementContext(Requirement requirement) { this.TenantId = requirement.TenantId; this.RequirementId = requirement.RequirementId; this.Description = requirement.Description; this.Time = requirement.Time; this.StatusId = requirement.Status; this.TypeId = requirement.TypeId; this.AssignedUserId = requirement.AssignedUser; this.Type = requirement.RequirementType.Name; this.Status = requirement.Status1.Name; this.AssignedUser = requirement.User.Username; //Get statuses that are available to the user StatusList = new List<Models.Status>(); ProjectManager.Models.DataClassesDataContext db = new ProjectManager.Models.DataClassesDataContext(); var availableStatuses = (from s in db.Status where s.TenantId == this.TenantId || s.TenantId == 1 select s); foreach (var status in availableStatuses) { StatusList.Add(status); } var project = (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.RequirementId == this.RequirementId && r.TenantId == this.TenantId select p).FirstOrDefault(); this.ProjectId = project.ProjectId; this.ProjectName = project.Name; db.Dispose(); }
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"); }
partial void DeleteRequirement(Requirement instance);
partial void UpdateRequirement(Requirement instance);
partial void InsertRequirement(Requirement instance);
private void detach_Requirements(Requirement entity) { this.SendPropertyChanging(); entity.Tenant = null; }
private void attach_Requirements(Requirement entity) { this.SendPropertyChanging(); entity.User = this; }