public ProjectFileViewModel(ProjectFilePath path, ShqContext db) { this.Name = System.IO.Path.GetFileName(path.Path); this.Path = path.Path; FileInfo fi = new FileInfo(path.FullPath); this.Size = fi.Length; this.CreatedTime = fi.CreationTime.ToString(); this.LastModfiedTime = fi.LastWriteTime.ToString(); Id = ShqConstants.GetPathId(path.Path); if (Id > 0) { this.Name = System.IO.Path.GetFileNameWithoutExtension(this.Name); var f = db.ProjectFiles.FirstOrDefault(item => item.Id == Id); if (f == null) { this.Name = ""; } else { this.Privilege = f.Privilege; CreatedBy = new ShqUserRequestViewModel(db.ShqUsers.Where(u => u.IdentityUser.Id == db.ProjectFiles.FirstOrDefault(item => item.Id == Id).CreatedById).FirstOrDefault(), db); CreatedTime = f.CreatedTime.ToString(); LastModifiedBy = new ShqUserRequestViewModel(db.ShqUsers.Where(u => u.IdentityUser.Id == db.ProjectFiles.FirstOrDefault(item => item.Id == Id).LastModifiedById).FirstOrDefault(), db); LastModfiedTime = f.LastModfiedTime.ToString(); this.Level = f.Level; } } }
public ProjectViewModel(Project project, ShqContext db) { if (project == null) { return; } Id = project.Id; Name = project.ProjectName; Description = project.Description; Type = project.Type; Tag = project.Tag; Status = project.Status; if (project.Type == "WorkProject") { Level = db.WorkProjects.FirstOrDefault(item => item.ProjectId == project.Id).Level; } var ps = db.ProjectShqUsers.Include("ShqUser").Where(item => item.ProjectId == project.Id).ToList(); foreach (var item in ps) { this.UsersPrivileges.Add(new ViewModels.UsersPrivileges() { RealName = item.ShqUser.RealName, EmailAddress = item.ShqUser.EmailAddress, Privilege = item.Privilege }); } CreatedBy = new ShqUserRequestViewModel(db.ShqUsers.Where(u => u.IdentityUser.Id == project.CreatedById).FirstOrDefault(), db); CreatedTime = project.CreatedTime.ToString(); LastModifiedBy = new ShqUserRequestViewModel(db.ShqUsers.Where(u => u.IdentityUser.Id == project.LastModifiedById).FirstOrDefault(), db); LastModfiedTime = project.LastModfiedTime.ToString(); }
public ShqUserRespondViewModel(ShqUser shqUser, ShqContext db) : base(shqUser, db) { CreatedBy = new ShqUserRequestViewModel(db.ShqUsers.Where(u => u.IdentityUser.Id == shqUser.CreatedById).FirstOrDefault(), db); CreatedTime = shqUser.CreatedTime.ToString(); LastModifiedBy = new ShqUserRequestViewModel(db.ShqUsers.Where(u => u.IdentityUser.Id == shqUser.LastModifiedById).FirstOrDefault(), db); LastModfiedTime = shqUser.LastModfiedTime.ToString(); }
public FTATreeViewModel(FTATree tree, ShqContext db) { Id = tree.Id; Content = tree.Content; ProjectId = tree.FTAProject.ProjectId; CreatedBy = new ShqUserRequestViewModel(db.ShqUsers.Where(u => u.IdentityUser.Id == tree.CreatedById).FirstOrDefault(), db); CreatedTime = tree.CreatedTime.ToString(); }
public WorkProjectViewModel(WorkProject workProject, ShqContext db) : base(workProject.Project, db) { WorkProjectTemplateId = workProject.WorkProjectTemplateId; Level = workProject.Level; FilesToCopyNum = workProject.FilesToCopyNum; FilesCopiedNum = workProject.FilesCopiedNum; var ftas = workProject.FTAProjects.ToList(); foreach (var f in ftas) { FTAProjects.Add(new ProjectViewModel(db.Projects.FirstOrDefault(item => item.Id == f.ProjectId), db)); } var fmeas = workProject.FMEAProjects.ToList(); foreach (var f in fmeas) { FMEAProjects.Add(new ProjectViewModel(db.Projects.FirstOrDefault(item => item.Id == f.ProjectId), db)); } }
public ShqUserRequestViewModel(ShqUser shqUser, ShqContext db) { if (shqUser == null) { return; } Status = shqUser.Status; //LoginName = shqUser.IdentityUser.UserName; RealName = shqUser.RealName; Description = shqUser.Description; EmailAddress = shqUser.EmailAddress; PhoneNumber = shqUser.PhoneNumber; Address = shqUser.Address; Gender = shqUser.Gender; JobLevel = shqUser.JobLevel; Department = shqUser.Department; shqUser.IdentityUser = db.Users.Find(shqUser.IdentityUserId); foreach (var r in shqUser.IdentityUser.Roles) { Roles.Add(db.Roles.Find(r.RoleId).Name); } }
public ProjectFolderViewModel(ProjectFilePath path, SearchOption searchOption, ShqContext db, int folderLevel = 1) { this.Path = path.Path; this.Name = System.IO.Path.GetFileName(path.Path); Id = ShqConstants.GetPathId(path.Path); if (Id > 0) { this.Name = System.IO.Path.GetFileNameWithoutExtension(this.Name); var f = db.ProjectFiles.FirstOrDefault(item => item.Id == Id); if (f == null) { this.Name = ""; } else { CreatedBy = new ShqUserRequestViewModel(db.ShqUsers.Where(u => u.IdentityUser.Id == db.ProjectFiles.FirstOrDefault(item => item.Id == Id).CreatedById).FirstOrDefault(), db); CreatedTime = f.CreatedTime.ToString(); LastModifiedBy = new ShqUserRequestViewModel(db.ShqUsers.Where(u => u.IdentityUser.Id == db.ProjectFiles.FirstOrDefault(item => item.Id == Id).LastModifiedById).FirstOrDefault(), db); LastModfiedTime = f.LastModfiedTime.ToString(); this.Privilege = f.Privilege; this.Level = f.Level; } } if (this.Name == "") { return; } if ((searchOption == SearchOption.TopDirectoryOnly && folderLevel == 1) || searchOption == SearchOption.AllDirectories) { string[] directory, files; directory = Directory.GetDirectories(path.FullPath); files = Directory.GetFiles(path.FullPath); if (directory != null && directory.Length > 0) { foreach (var d in directory) { var pf = new ProjectFolderViewModel(new ProjectFilePath { FullPath = d, Path = System.IO.Path.Combine(path.Path, System.IO.Path.GetFileName(d)) }, searchOption, db, folderLevel); if (pf.Name != "") { this.SubFolders.Add(pf); } } if (this.SubFolders != null && this.SubFolders.Count > 0) { this.SubFolders.Sort((x, y) => x.Name.CompareTo(y.Name)); } } if (files != null && files.Length > 0) { foreach (var f in files) { var ff = new ProjectFileViewModel(new ProjectFilePath { FullPath = f, Path = System.IO.Path.Combine(path.Path, System.IO.Path.GetFileName(f)) }, db); if (ff.Name != "") { this.Files.Add(ff); } } if (this.Files != null && this.Files.Count > 0) { this.Files.Sort((x, y) => x.Name.CompareTo(y.Name)); } } folderLevel--; } }
public static List <ProjectViewModel> ToProjectViewModelList(List <Project> projects, ShqContext db) { List <ProjectViewModel> result = new List <ProjectViewModel>(); foreach (var item in projects) { result.Add(new ProjectViewModel(item, db)); } return(result); }