private bool HasAccess(string id, out Template template) { template = null; string userId = User.Identity.GetUserId(); var user = _userRepository.Find(userId); if (user == null) return false; template = _templateRepository.Find(id); if (template == null) return true; // allow create // user must be member return template.OrganizationId == user.Id || user.Organizations.Contains(template.OrganizationId); }
public Template GenerateTemplate(string organizationId) { if (organizationId == null) throw new ArgumentNullException("organizationId"); var template = new Template { Id = ObjectId.GenerateNewId().ToString(), Name = "Sample Template", Description = "Generated Sample Template", OrganizationId = organizationId, Created = DateTime.Now, Creator = UserName.Current(), Updated = DateTime.Now, Updater = UserName.Current() }; var presentationFactor = new Factor { Id = ObjectId.GenerateNewId().ToString(), Name = "Presentation Factor", VerySimple = 2, Simple = 4, Medium = 8, Complex = 16, VeryComplex = 32, }; template.Factors.Add(presentationFactor); var backendFactor = new Factor { Id = ObjectId.GenerateNewId().ToString(), Name = "Back-End Logic Factor", VerySimple = 2, Simple = 4, Medium = 8, Complex = 16, VeryComplex = 32, }; template.Factors.Add(backendFactor); var dataFactor = new Factor { Id = ObjectId.GenerateNewId().ToString(), Name = "Data Model Factor", VerySimple = 1, Simple = 2, Medium = 4, Complex = 8, VeryComplex = 16, }; template.Factors.Add(dataFactor); return template; }