public ActionResult Details(int id) { var model = new ProjectFormModel(); var project = ProjectRepository.ProjectFetch(id); model.Title = string.Format("Project {0}", project.Name); model.Project = project; model.Notes = NoteRepository.NoteFetchInfoList(id, SourceType.Project); model.Attachments = AttachmentRepository.AttachmentFetchInfoList( model.Notes.Select(row => row.NoteId).Distinct().ToArray(), SourceType.Note); model.Sprints = SprintRepository.SprintFetchInfoList(project); model.Statuses = StatusRepository.StatusFetchInfoList(id); model.Stories = StoryRepository.StoryFetchInfoList(project, false); model.Users = ProjectUserRepository.ProjectUserFetchInfoList(id); model.TimelineListModel = new TimelineListModel { Timelines = TimelineRepository.TimelineFetchInfoList(project), SourceId = project.SourceId, SourceTypeId = (int)project.SourceType }; model.Actions.Add("Edit this project", Url.Action("Edit", new { id }), "primary"); model.Actions.Add("Add a story", Url.Action("Create", "Story", new { projectId = id })); model.Actions.Add("Add a sprint", Url.Action("Create", "Sprint", new { projectId = id })); model.Actions.Add("Add an email", string.Empty); model.Actions.Add("Add a note", Url.Action("Create", "Note", new { sourceId = id, sourceTypeId = (int)SourceType.Project })); model.Actions.Add("Add a collaborator", Url.Action("Create", "ProjectUser", new { projectId = id })); model.Actions.Add("Add a status", Url.Action("Create", "Status", new { projectId = id })); return(this.View(model)); }
public void TestUserWithAValueOfNullDoesNotSave() { Attachment attachment = null; try { #region Arrange attachment = GetValid(9); attachment.User = null; #endregion Arrange #region Act AttachmentRepository.DbContext.BeginTransaction(); AttachmentRepository.EnsurePersistent(attachment); AttachmentRepository.DbContext.CommitTransaction(); #endregion Act } catch (Exception) { Assert.IsNotNull(attachment); Assert.AreEqual(attachment.User, null); var results = attachment.ValidationResults().AsMessageList(); results.AssertErrorsAre("The User field is required."); Assert.IsTrue(attachment.IsTransient()); Assert.IsFalse(attachment.IsValid()); throw; } }
/// <summary> /// 绑定当前记录所用到的附件 /// </summary> /// <param name="id">当前记录的Id</param> /// <param name="url">当前记录图片地址,以“,”为分割</param> /// <param name="content">编辑器中的内容(如果有插入图片)</param> /// <param name="split">分割符</param> public async Task <string> BoundAttachment(long id, string url, string content = "", char split = ',') { if (!string.IsNullOrEmpty(content)) { url = url + split + StringUtility.GetEditorImgUrl(content); } if (id < 1 || string.IsNullOrEmpty(url)) { return(""); } var filePaths = url.Split(split) .Where(m => !string.IsNullOrEmpty(m)) .ToArray(); if (filePaths.Length == 0) { return(""); } var list = await AttachmentRepository.GetListAsync(filePaths); if (!list.Any()) { return(""); } foreach (var item in list) { item.SourceId = id; } await AttachmentRepository.SaveChangesAsync(); return(""); }
public void TestContentTypeWithSpacesOnlyDoesNotSave() { Attachment attachment = null; try { #region Arrange attachment = GetValid(9); attachment.ContentType = " "; #endregion Arrange #region Act AttachmentRepository.DbContext.BeginTransaction(); AttachmentRepository.EnsurePersistent(attachment); AttachmentRepository.DbContext.CommitTransaction(); #endregion Act } catch (Exception) { Assert.IsNotNull(attachment); var results = attachment.ValidationResults().AsMessageList(); results.AssertErrorsAre(string.Format("The {0} field is required.", "ContentType")); Assert.IsTrue(attachment.IsTransient()); Assert.IsFalse(attachment.IsValid()); throw; } }
public void CRUD_One_Attachment_And_Fetch_Runs_Successfully() { var connectionManager = new ConnectionManager(DbFile.GetConnectionString("testdb.db")); var repository = new AttachmentRepository(connectionManager); var entry = new Attachment { FileName = "filename.pdf", Description = "New Attachment", Extension = "pdf" }; repository.InsertOne(entry); var insertedEntity = repository.GetOne(1); Assert.IsNotNull(entry); insertedEntity.Description = "Modified Attachment"; repository.UpdateOne(insertedEntity); var updatedEntity = repository.GetOne(1); Assert.That(updatedEntity.Description, Is.EqualTo("Modified Attachment")); repository.DeleteOne(updatedEntity); var deletedEntity = repository.GetOne(insertedEntity.Id); Assert.IsNull(deletedEntity); }
public async void FindAsync_GivenAttachmentExists_ReturnsAttachment() { var attachment = new Attachment() { Id = 1, Description = "Foo", Data = "thurfh", ProjectId = 1, Project = new Project() { Id = 1 }, Type = (int)AttachmentTypes.PDF }; var contextMock = new Mock <ICrowdSparkContext>(); contextMock.Setup(c => c.Attachments.FindAsync(1)).ReturnsAsync(attachment); using (var repo = new AttachmentRepository(contextMock.Object)) { var result = await repo.FindAsync(1); var expected = new AttachmentDTO() { Id = 1, Description = "Foo", Data = "thurfh", ProjectId = 1, Type = (int)AttachmentTypes.PDF }; result.ShouldBeEquivalentTo(expected); } }
public async Task <bool> Save(HttpPostedFileBase postedFile, Attachment oAtt, string fCats = null) { if (postedFile == null || postedFile.ContentLength <= 0) { return(false); } var refFileName = ""; try { oAtt.Name = Path.GetFileNameWithoutExtension(postedFile.FileName); if (oAtt.Name != null && oAtt.Name.Length > 50) { oAtt.Name = oAtt.Name.Substring(0, 50); } var fileName = string.Format("{0}{1}", DateTime.Now.ToString("HHmmss"), Math.Abs((oAtt.Name + Guid.NewGuid()).GetHashCode())); refFileName = SaveFile(postedFile, fCats, fileName); oAtt.FilePath = refFileName; oAtt.FileSize = postedFile.ContentLength; oAtt.FileExt = Path.GetExtension(postedFile.FileName); oAtt.ViewCount = 0; oAtt.SortIndex = 0; await AttachmentRepository.SaveAsync(oAtt); } catch (Exception ex) { var f = GetFullPath(refFileName); if (File.Exists(f)) { File.Delete(f); } return(false); } return(true); }
public void TestAttachmentWithNewUserDoesNotCascadeSave() { var thisFar = false; try { #region Arrange var record = GetValid(9); record.User = new User("NoOne"); #endregion Arrange #region Act AttachmentRepository.DbContext.BeginTransaction(); thisFar = true; AttachmentRepository.EnsurePersistent(record); AttachmentRepository.DbContext.CommitTransaction(); #endregion Act } catch (Exception) { Assert.IsTrue(thisFar); throw; } }
public LmPlatformRepositoriesContainer() { UsersRepository = new UsersRepository(_dataContext); BugsRepository = new BugsRepository(_dataContext); BugLogsRepository = new BugLogsRepository(_dataContext); GroupsRepository = new GroupsRepository(_dataContext); ProjectsRepository = new ProjectsRepository(_dataContext); ProjectUsersRepository = new ProjectUsersRepository(_dataContext); ProjectCommentsRepository = new ProjectCommentsRepository(_dataContext); StudentsRepository = new StudentsRepository(_dataContext); SubjectRepository = new SubjectRepository(_dataContext); TestsRepository = new TestsRepository(_dataContext); TestUnlocksRepository = new TestUnlockRepository(_dataContext); QuestionsRepository = new QuestionsRepository(_dataContext); UsersRepository = new UsersRepository(_dataContext); ModulesRepository = new ModulesRepository(_dataContext); LecturerRepository = new LecturerRepository(_dataContext); MessageRepository = new MessageRepository(_dataContext); MaterialsRepository = new MaterialsRepository(_dataContext); FoldersRepository = new FoldersRepository(_dataContext); SubGroupRepository = new SubGroupRepository(_dataContext); AttachmentRepository = new AttachmentRepository(_dataContext); LecturesRepository = new LecturesRepository(_dataContext); LabsRepository = new LabsRepository(_dataContext); ProjectUsersRepository = new ProjectUsersRepository(_dataContext); PracticalRepository = new PracticalRepository(_dataContext); ConceptRepository = new ConceptRepository(_dataContext); WatchingTimeRepository = new WatchingTimeRepository(_dataContext); TestQuestionPassResultsRepository = new TestQuestionPassResultsRepository(_dataContext); //todo UNUSED ProjectMatrixRequirementsRepository = new ProjectMatrixRequirementsRepository(_dataContext); }
/// <summary> /// 根据模具号、操作员号、起止日期、页码信息获得模具放行信息 /// </summary> /// <param name="moldNR">模具号</param> /// <returns>模具放行信息列表</returns> public List <MoldReleaseInfo> GetMoldReleaseInfoByMoldNR(string moldNR, string operatorId, DateTime?startDate, DateTime?endDate) { using (IUnitOfWork unitwork = MSSqlHelper.DataContext()) { IReportRepository reportRep = new ReportRepository(unitwork); List <ReportView> reports = reportRep.GetReportViewByMoldNR(moldNR, operatorId, startDate, endDate); IAttachmentRepository attachRep = new AttachmentRepository(unitwork); List <MoldReleaseInfo> moldReleaseInfos = new List <MoldReleaseInfo>(); foreach (ReportView r in reports) { MoldReleaseInfo moldReleaseInfo = new MoldReleaseInfo() { TesterName = r.Name, TesterNR = r.OperatorID, Date = r.Date, TargetNR = r.MoldID, ReportType = r.ReportType, ReportTypeCN = r.ReportTypeCN, Attach = attachRep.GetByMasterNR(r.ReportId.ToString()) }; moldReleaseInfos.Add(moldReleaseInfo); } return(moldReleaseInfos); } }
public ApplicationDataService(IDatabase database) { Attachments = new AttachmentRepository(database); Chats = new ChatRepository(database); Messages = new MessageRepository(database); Users = new UserRepository(database); }
public void TestCategoryWithTooLongValueDoesNotSave() { Attachment attachment = null; try { #region Arrange attachment = GetValid(9); attachment.Category = "x".RepeatTimes((50 + 1)); #endregion Arrange #region Act AttachmentRepository.DbContext.BeginTransaction(); AttachmentRepository.EnsurePersistent(attachment); AttachmentRepository.DbContext.CommitTransaction(); #endregion Act } catch (Exception) { Assert.IsNotNull(attachment); Assert.AreEqual(50 + 1, attachment.Category.Length); var results = attachment.ValidationResults().AsMessageList(); results.AssertErrorsAre(string.Format("The field {0} must be a string with a maximum length of {1}.", "Category", "50")); Assert.IsTrue(attachment.IsTransient()); Assert.IsFalse(attachment.IsValid()); throw; } }
/// <summary> /// 根据模具号获得模具基本信息 /// </summary> /// <param name="moldNR">模具号</param> /// <returns>模具基本信息</returns> public MoldBaseInfo GetMoldBaseInfoByNR(string moldNR) { using (IUnitOfWork unitwork = MSSqlHelper.DataContext()) { IMoldRepository moldRepostitory = new MoldRepository(unitwork); IAttachmentRepository attachRep = new AttachmentRepository(unitwork); IPositionRepository posiRep = new PositionRepository(unitwork); MoldView m = moldRepostitory.GetMoldViewByMoldNR(moldNR); if (m != null) { MoldBaseInfo mb = new MoldBaseInfo() { MoldNR = m.MoldNR, Name = m.Name, Type = m.TypeName, Position = posiRep.GetByFacilictyNR(moldNR).PositionNR, Producer = m.Producer, Material = m.Material, Weight = m.Weight == null ? string.Empty : m.Weight.ToString(), State = m.State, StateCN = m.StateCN, MaxLendHour = (m.MaxLendHour.HasValue ? m.MaxLendHour.Value : 0), ProjectId = m.ProjectID, ProjectName = m.ProjectName, Attach = attachRep.GetByMasterNR(moldNR) }; return(mb); } return(null); } }
public UnitOfWork( WordPressDbContext context, //IOptions<AppSettings> appSettings, ITermRepository termRepository, MetadataRepository metadataRepository, IMetadataService metadataService, OptionRepository optionRepository, AttachmentRepository attachmentRepository, ILoggerFactory loggerFactory //IOptions<ClientSettings> clientSettings, //RazorViewRenderer razorView ) { _context = context; _context.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; //AppSettings = appSettings.Value; Posts = new PostRepository(_context); //TermService = new TermService(termRepository, memoryCache); MetadataService = metadataService; TermTaxonomies = new TermTaxonomyRepository(_context); Options = new OptionRepository(_context); Attachments = new AttachmentRepository(_context); //RazorView = razorView; // this must be last one so the all services are working in this service }
public async void DeleteAsync_GivenAttachmentExists_DeletesAttachmentAndReturnsSuccess() { var existingAttachment = new Attachment { Data = "sgivehfuihvuaeirhvuhrsuvinfi", Description = "Attachment", Type = (int)AttachmentTypes.BITMAP, ProjectId = 1 }; var user = new User() { Id = 1, Firstname = "John", Surname = "Smith", AzureUId = "rfaweaw", Mail = "*****@*****.**" }; var project = new Project() { Id = 1, Title = "Foo", Description = "Bar", Creator = user, CreatedDate = System.DateTime.UtcNow }; context.Projects.Add(project); var attachment = context.Attachments.Add(existingAttachment); context.SaveChanges(); //SanityCheck Assert.NotNull(context.Attachments.Find(attachment.Entity.Id)); using (var repository = new AttachmentRepository(context)) { var success = await repository.DeleteAsync(attachment.Entity.Id); Assert.True(success); Assert.Null(context.Attachments.Find(attachment.Entity.Id)); } }
public async void CreateAsync_GivenValidAttachment_ReturnsNewAttachmentId() { var attachmentToCreate = new AttachmentCreateDTO { Description = "An example attachment", Data = "fuvwygwiu gbuywgykaguygdchjbaeiuyxgciuyadhviu bwrhjdsiyeabfcuyuw wyadvfjcvyut3er78t2euabdcbeaiyc eqdcgfw", Type = (int)AttachmentTypes.BITMAP, ProjectId = 1 }; var user = new User() { Id = 1, Firstname = "John", Surname = "Smith", AzureUId = "rfaweaw", Mail = "*****@*****.**" }; var project = new Project() { Id = 1, Title = "Foo", Description = "Bar", Creator = user, CreatedDate = System.DateTime.UtcNow }; context.Projects.Add(project); context.SaveChanges(); //SanityCheck Assert.NotNull(context.Projects.AsNoTracking().Where(p => p.Id == 1).First()); using (var repository = new AttachmentRepository(context)) { var id = await repository.CreateAsync(attachmentToCreate); Assert.Equal((await context.Attachments.FirstAsync()).Id, id); } }
public void TestAttachmentWithNewOrderDoesNotSave() { var thisFar = false; try { #region Arrange var record = GetValid(9); record.Order = new Order(); thisFar = true; #endregion Arrange #region Act AttachmentRepository.DbContext.BeginTransaction(); AttachmentRepository.EnsurePersistent(record); AttachmentRepository.DbContext.CommitTransaction(); #endregion Act } catch (Exception ex) { Assert.IsTrue(thisFar); Assert.IsNotNull(ex); Assert.AreEqual("object references an unsaved transient instance - save the transient instance before flushing or set cascade action for the property to something that would make it autosave. Type: Purchasing.Core.Domain.Order, Entity: Purchasing.Core.Domain.Order", ex.Message); throw; } }
public void AttachmentRepositoryConstructorTest1() { string name = string.Empty; // TODO: Initialize to an appropriate value string filePath = string.Empty; // TODO: Initialize to an appropriate value AttachmentRepository target = new AttachmentRepository(name, filePath); Assert.Inconclusive("TODO: Implement code to verify target"); }
public static Attachment AttachmentAdd(int sourceId, SourceType sourceType) { var attachment = AttachmentTestHelper.AttachmentNew(sourceId, sourceType); attachment = AttachmentRepository.AttachmentSave(attachment); return(attachment); }
public static Attachment AttachmentNew(int sourceId, SourceType sourceType) { var attachment = AttachmentRepository.AttachmentNew(sourceId, sourceType); attachment.Name = DataHelper.RandomString(50); return(attachment); }
// GET: Attachment public ActionResult Index(string id) { var vm = new AttachmentViewModel(); vm.UID = new Guid(id); vm.Attachments = AttachmentRepository.GetAttachments(vm.UID); return(View(vm)); }
public ArticleService(ArticleRepository articleRepository, IMapper mapper, AttachmentRepository attachmentRepository, CategoryRepository categoryRepository) { _articleRepository = articleRepository; _mapper = mapper; _attachmentRepository = attachmentRepository; _categoryRepository = categoryRepository; }
public ActionResult Details(int id) { var attachment = AttachmentRepository.AttachmentFetch(id); var ms = new System.IO.MemoryStream(attachment.FileData, 0, attachment.FileData.Length); return(new FileStreamResult(ms, attachment.FileType)); }
public async void ReadForProjectAsync_GivenAttachmentsExist_ReturnsAttachments() { var user = new User() { Id = 1, Firstname = "Bob", Surname = "Smith", AzureUId = "foo", Mail = "*****@*****.**" }; var project1 = new Project() { Id = 1, Title = "Foo", Description = "Bar", Creator = user, CreatedDate = System.DateTime.UtcNow }; var project2 = new Project() { Id = 2, Title = "Foo2", Description = "Bar", Creator = user, CreatedDate = System.DateTime.UtcNow }; var attachment1 = new Attachment() { Id = 1, Description = "Foo", Data = "thurfh", ProjectId = 1, Project = project1, Type = (int)AttachmentTypes.PDF }; var attachment2 = new Attachment() { Id = 2, Description = "Moo", Data = "thurfh", ProjectId = 1, Project = project1, Type = (int)AttachmentTypes.PDF }; var attachment3 = new Attachment() { Id = 3, Description = "Moo", Data = "thurfh", ProjectId = 2, Project = project2, Type = (int)AttachmentTypes.PDF }; context.Users.Add(user); context.Projects.Add(project1); context.Projects.Add(project2); context.Attachments.Add(attachment1); context.Attachments.Add(attachment2); context.Attachments.Add(attachment3); context.SaveChanges(); //SanityCheck Assert.Equal(3, context.Attachments.ToArray().Count()); using (var repo = new AttachmentRepository(context)) { var results = await repo.ReadForProjectAsync(1); var expected1 = new AttachmentDTO() { Id = 1, Description = "Foo", Data = "thurfh", ProjectId = 1, Type = (int)AttachmentTypes.PDF }; var expected2 = new AttachmentDTO() { Id = 2, Description = "Moo", Data = "thurfh", ProjectId = 1, Type = (int)AttachmentTypes.PDF }; results.ToArray()[0].ShouldBeEquivalentTo(expected1); results.ToArray()[1].ShouldBeEquivalentTo(expected2); Assert.Equal(2, results.Count()); } }
public ActionResult Delete(int id, FormCollection collection) { var attachment = AttachmentRepository.AttachmentFetch(id); var note = NoteRepository.NoteFetch(attachment.SourceId); AttachmentRepository.AttachmentDelete(id); return(this.RedirectToAction("Details", note.SourceTypeName, new { id = note.SourceId })); }
public UnitOfWork(OfficeAttendenceSystemDbContext DbContext) { _DbContext = DbContext; Departments = new DepartmentRepository(_DbContext); Employees = new EmployeeRepository(_DbContext); Users = new UserRepository(_DbContext); Attendances = new AttendanceRepository(_DbContext); Attachments = new AttachmentRepository(_DbContext); }
/// <summary> /// 根据报告号获取附件 /// </summary> /// <param name="reportId">报告号</param> /// <returns>附件列表</returns> public List <Attachment> GetAttachmentById(Guid reportId) { using (IUnitOfWork unitwork = MSSqlHelper.DataContext()) { IAttachmentRepository reportAttachRep = new AttachmentRepository(unitwork); List <Attachment> attaches = reportAttachRep.GetByMasterNR(reportId.ToString()); return(attaches); } }
private void Init(ApplicationDbContext context) { Attachments = new AttachmentRepository(context); Employees = new EmployeeRepository(context); Flowers = new FlowerRepository(context); Notifications = new NotificationRepository(context); TempFiles = new TempFileRepository(context); Requests = new RequestRepository(context); }
public string ExportOfflinePackage() { var webRootPath = PlatformServices.Default.Application.ApplicationBasePath; var dir = Path.Combine(webRootPath, "files", "export"); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var result = SearchDic(new SearchArgs <Material>() { Pagination = false }); var fileName = $"MaterialConfig_{DateTime.Now.ToString("yyyyMMddHHmmss")}.json"; var filePath = Path.Combine(dir, fileName); Attachment attachment = null; if (File.Exists(filePath)) { attachment = AttachmentRepository.SingleOrDefault(x => x.OrginalFileName == fileName); if (attachment != null) { attachment.DownloadTimes++; return(attachment.FileGuid); } } var dic = result.Items.ToDictionary(item => (string)item["PartNumber"]); var s = JsonUtil.Serialize(dic, prettify: true); File.WriteAllText(filePath, s, Encoding.UTF8); var md5 = MD5Util.MD5Stream(filePath); var size = new FileInfo(filePath).Length; attachment = new Attachment() { Type = "export", ContentType = "application/json", DownloadTimes = 0, FileExtention = ".json", FileName = fileName, OrginalFileName = "MaterialConfig.json", MD5 = md5, Size = size, }; var user = GetUserIdentity(); if (user != null) { attachment.CreateTime = DateTime.Now; attachment.CreateUserName = user.UserName; attachment.ModifyTime = DateTime.Now; attachment.ModifyUserName = user.UserName; } AttachmentRepository.Insert(attachment); return(attachment.FileGuid); }
public AssetEntryUnitOfWork(AssetDbContext context) { _context = context; AssetEntry = new AssetEntryRepository(_context); Finance = new FinanceRepository(_context); ServiceOrRepairing = new ServiceOrRepairingRepository(_context); Note = new NoteRepository(_context); Attchment = new AttachmentRepository(_context); }