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 string InsertOrUpdate(AttachmentDTO attachment) { try { var validate = Validate(attachment); if (!string.IsNullOrEmpty(validate)) { return(validate); } if (ObjectExists(attachment)) { return(GenericMessages.DatabaseErrorRecordAlreadyExists); } attachment.Synced = false; _attachmentRepository.InsertUpdate(attachment); _unitOfWork.Commit(); return(string.Empty); } catch (Exception exception) { return(exception.Message); } }
public async Task <int> SaveEvent([FromBody] Event data) { int eventId = 0; try { // mappper to convert to DTO objects var eventData = _mapper.Map <Event, EventDTO>(data); var comment = _mapper.Map <Comment, CommentDTO>(data.Comments[0]); var attachment = new AttachmentDTO(); if (data.Attachments != null && data.Attachments.Count > 0) { attachment = _mapper.Map <Attachment, AttachmentDTO>(data.Attachments[0]); } // call repository method to save an event eventId = await _eventRepository.AddEvent(eventData, comment, attachment); } catch (Exception ex) { using (_logger.BeginScope(new Dictionary <string, object> { { "Events", "Save Event" } })) { _logger.LogError(ex.Message); } // throw ex; } return(eventId); }
public HttpResponseMessage ModifyAttachment([FromBody] AttachmentDTO attachment) { var originalAttachment = DTOFactory.Parse(attachment); UnitOfWork.AttachmentRepository.Update(originalAttachment); return(Request.CreateResponse(HttpStatusCode.OK)); }
public bool DeleteAttachmentes(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork) { List <AttachmentDTO> addressDtos = sourceUnitOfWork.Repository <AttachmentDTO>() .Query() .Get(-1) .ToList(); foreach (AttachmentDTO source in addressDtos) { AttachmentDTO adr1 = source; var destination = destinationUnitOfWork.Repository <AttachmentDTO>() .Query() .Filter(i => i.RowGuid == adr1.RowGuid) .Get(-1)//don't use .Get() to make sure both sides of data are disabled .FirstOrDefault(); if (destination != null) { sourceUnitOfWork.Repository <AttachmentDTO>().Delete(source.Id); destinationUnitOfWork.Repository <AttachmentDTO>().Delete(destination.Id); sourceUnitOfWork.Commit(); destinationUnitOfWork.Commit(); } } return(true); }
public string Disable(AttachmentDTO attachment) { if (attachment == null) { return(GenericMessages.ObjectIsNull); } string stat; var iDbContext = DbContextUtil.GetDbContextInstance(); try { _attachmentRepository.Update(attachment); _unitOfWork.Commit(); stat = string.Empty; } catch (Exception exception) { stat = exception.Message; } finally { iDbContext.Dispose(); } return(stat); }
public void AddNewAttachment(AttachmentDTO newAttachment) { Mapper.Reset(); Mapper.Initialize(cfg => cfg.CreateMap(typeof(AttachmentDTO), typeof(Attachment))); Attachment attachmentEntyti = (Attachment)Mapper.Map(newAttachment, typeof(AttachmentDTO), typeof(Attachment)); AttachmentRepos.Add(attachmentEntyti); }
public static Attachment ToAttachment(this AttachmentDTO dto) { if (dto == null) { return((Attachment)null); } return(new Attachment(dto.Stream, dto.Name, dto.MimeType)); }
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 string Validate(AttachmentDTO attachment) { if (null == attachment) { return(GenericMessages.ObjectIsNull); } return(string.Empty); }
public Attachment MapFrom(AttachmentDTO entity) { return(new Attachment() { FileName = entity.FileName, SizeMb = entity.SizeMb, SizeKb = entity.SizeKb }); }
private Attachment ConvertAttachment(AttachmentDTO attachmentDTO) { return(new Attachment() { Filename = attachmentDTO.Name, Content = Convert.ToBase64String(GetMemoryStream(attachmentDTO.Stream).ToArray()), Type = attachmentDTO.MimeType }); }
public ActionResult ShowAttachment(int id) { //List<AttachmentDTO> attachments = InputDAC.GetAttachments(216); //MemoryStream ms = new MemoryStream(attachments[0].BinaryData); AttachmentDTO attachment = InputDAC.GetAttachment(id); MemoryStream ms = new MemoryStream(attachment.BinaryData); return(new ImageResult(ms, FileTypeHelper.GetContentType(attachment.Filename))); }
/// <summary> /// Save an event with comment and attachment /// </summary> /// <param name="evnt"></param> /// <param name="comment"></param> /// <param name="attachment"></param> /// <returns></returns> public async Task <int> AddEvent(EventDTO evnt, CommentDTO comment, AttachmentDTO attachment) { using (var connection = CreateConnection()) { // Get CST time DateTime timeUtc = DateTime.UtcNow; TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, cstZone); // Save an event by calling stored proc var newEventId = await connection.QuerySingleAsync <int>(StoredProcedureNames.SAVE_EVENT, new { event_id = evnt.EVENT_ID, variance_duration_id = evnt.VARIANCE_DURATION_ID, variance_cost_id = evnt.VARIANCE_COST_ID, title = evnt.TITLE, level1 = evnt.LEVEL1, level2 = evnt.LEVEL2, responsible_party = evnt.RESPONSIBLE_PARTY, variance_type = evnt.VARIANCE_TYPE, event_status = evnt.EventStatus, dateTimeNow = cstTime, userName = evnt.LOGGED_IN_USERNAME, closed_status = evnt.ClosedStatus }, commandType : CommandType.StoredProcedure).ConfigureAwait(false); // Save comment for an event var commentId = await connection.ExecuteAsync(StoredProcedureNames.SAVE_COMMENT, new { event_Id = newEventId, comment_id = (evnt.EVENT_ID > 0 && comment.COMMENT_ID != Guid.Empty && comment.COMMENT_ID != null) ? comment.COMMENT_ID : Guid.NewGuid(), comment_desc = comment.COMMENT, dateTimeNow = cstTime, userName = evnt.LOGGED_IN_USERNAME }, commandType : CommandType.StoredProcedure).ConfigureAwait(false); var attachmentId = await connection.ExecuteAsync(StoredProcedureNames.SAVE_ATTACHMENT, new { event_Id = newEventId, attachment_Id = (evnt.EVENT_ID > 0 && attachment.ATTACHMENT_ID != Guid.Empty && attachment.ATTACHMENT_ID != null) ? attachment.ATTACHMENT_ID : Guid.NewGuid(), path = attachment.ATTACHMENT_PATH, dateTimeNow = cstTime, userName = evnt.LOGGED_IN_USERNAME }, commandType : CommandType.StoredProcedure).ConfigureAwait(false); // return created eventid return(newEventId); } }
private AttachmentDTO ToDTO(AttachmentEntity entity) { AttachmentDTO dto = new AttachmentDTO(); dto.Id = entity.Id; dto.Name = entity.Name; dto.IconName = entity.IconName; dto.CreateDateTime = entity.CreateDateTIme; return(dto); }
private AttachmentDTO ToDTO(AttachmentEntity att) { AttachmentDTO dto = new AttachmentDTO(); dto.CreateDateTime = att.CreateDateTime; dto.IconName = att.IconName; dto.Id = att.Id; dto.Name = att.Name; return(dto); }
public AttachmentDTO ToDTO(AttachmentEntity attachment) { AttachmentDTO attachmentDto = new AttachmentDTO(); attachmentDto.IconName = attachment.IconName; attachmentDto.Name = attachment.Name; attachmentDto.Id = attachment.Id; attachmentDto.CreateDateTime = attachmentDto.CreateDateTime; return(attachmentDto); }
public AttachmentDTO DTO(AttachmentEntity entity) { AttachmentDTO attachment = new AttachmentDTO() { Id = entity.Id, IconName = entity.IconName, Name = entity.Name, CreateDateTime = entity.CreateDateTime }; return(attachment); }
private AttachmentDTO ToDTO(AttachmentEntity att) { var dto = new AttachmentDTO { CreateDateTime = att.CreateDateTime, IconName = att.IconName, Id = att.Id, Name = att.Name, }; return(dto); }
private static AttachmentDTO Clone(AttachmentDTO attachmentDto) { return(new AttachmentDTO { OriginalFileName = attachmentDto.OriginalFileName, UniqueFileName = attachmentDto.UniqueFileName, CreateDate = attachmentDto.CreateDate, Description = attachmentDto.Description, OwnerID = attachmentDto.OwnerID, AttachmentFileID = attachmentDto.AttachmentFileID, MessageID = attachmentDto.MessageID }); }
public HttpResponseMessage AddAttachment([FromBody] AttachmentDTO attachmentDTO) { Attachment entity = DTOFactory.Parse(attachmentDTO); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not parse an User")); } entity.UniqueName = WebConfigurationManager.AppSettings["serverFileDirectory"] + entity.Name; UnitOfWork.AttachmentRepository.Insert(entity); return(Request.CreateResponse(HttpStatusCode.Created, DTOFactory.Create(entity))); }
public async Task <AttachmentDTO> CreateAsync(AttachmentDTO attachmentDTO) { var attachment = this.attachmentDTOMapper.MapFrom(attachmentDTO); if (attachment == null) { throw new ArgumentNullException(); } this.dbcontext.Attachments.Add(attachment); await this.dbcontext.SaveChangesAsync(); return(this.attachmentDTOMapper.MapFrom(attachment)); }
private void ExecuteShowEmployeeShortImageViewCommand() { var file = new OpenFileDialog { Filter = "Image Files(*.png;*.jpg; *.jpeg)|*.png;*.jpg; *.jpeg" }; var result = file.ShowDialog(); if (result != null && ((bool)result && File.Exists(file.FileName))) { EmployeeShortImage = new BitmapImage(new Uri(file.FileName, true)); if (!SaveMember(null)) { MessageBox.Show("Can't Save Member Data, try again later"); } if (EmployeeShortImage != null && EmployeeShortImage.UriSource != null) { _photoAttachment = new AttachmentDTO { AttachedFile = ImageUtil.ToBytes(EmployeeShortImage) }; SelectedMember.Photo = _photoAttachment; var stat = _memberService.InsertOrUpdate(SelectedMember); if (!string.IsNullOrEmpty(stat)) { MessageBox.Show("Can't Add Photo, try again later"); } } ////if (EmployeeShortImage != null && EmployeeShortImage.UriSource != null) ////{ //// _photoAttachment = _attachmentService.Find(SelectedMember.PhotoId.ToString()); //// if (_photoAttachment != null) //// { //// _photoAttachment.AttachedFile = ImageUtil.ToBytes(EmployeeShortImage); //// SelectedMember.Photo = _photoAttachment; //// } //// else //// { //// _photoAttachment = new AttachmentDTO //// { //// AttachedFile = ImageUtil.ToBytes(EmployeeShortImage) //// }; //// SelectedMember.Photo = _photoAttachment; //// } ////} } }
public async Task <int> Create(AttachmentDTO DTO) { using SqlConnection conn = new SqlConnection(_connectionString); return(await conn.ExecuteScalarAsync <int>(@"INSERT INTO [testing].[Attachments]( [FileName], [OriginalFileName], [FilePath], [DateAdded]) VALUES( @FileName, @OriginalFileName, @FilePath, @DateAdded) SELECT SCOPE_IDENTITY()", new { DTO.FileName, DTO.OriginalFileName, DTO.FilePath, DTO.DateAdded })); }
public static void StoreAttachment(AttachmentDTO attachment) { using (SqlConnection cnn = WordDAC.NewConnection) using (SqlCommand cmd = cnn.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "[input_pkg.store_attachment]"; cmd.Parameters.AddWithValue("@analysis_input_id", attachment.AnalysisInputID); cmd.Parameters.AddWithValue("@title", attachment.Title); cmd.Parameters.AddWithValue("@filename", attachment.Filename); cmd.Parameters.AddWithValue("@binary_data", attachment.BinaryData); cnn.Open(); cmd.ExecuteNonQuery(); } }
public async Task <IActionResult> CreateAtt([FromForm] AttachmentDTO attachment, int id) { using (var ms = new MemoryStream()) { foreach (var att in attachment.File) { att.CopyTo(ms); var fileBytes = ms.ToArray(); var attachmentDb = new attachmentforsaveDTO { BinaryFile = fileBytes, EmailId = id }; var attachementForSave = _mapper.Map <models.Attachment>(attachmentDb); await _repository.SendAttachments(attachementForSave); } return(Ok()); } }
public void TryModifyAttachment_Test() { _controller.Request = new HttpRequestMessage(); _controller.Configuration = new System.Web.Http.HttpConfiguration(); AttachmentDTO attachmentDTO = new AttachmentDTO { Id = 69, AssessmentId = 1109, Name = "Lerman J., Miller R. - Programming Entity Framework. Code First - 2011.pdf", UniqueName = "~/Files/Lerman J., Miller R. - Programming Entity Framework. Code First - 2011.pdf", Comment = "Interesting book.", Size = 6622819 }; HttpResponseMessage response = _controller.ModifyAttachment(attachmentDTO); }
public async Task <bool> UpdateAsync(AttachmentDTO details) { var attachmentToUpdate = await _context.Attachments.FindAsync(details.Id); if (attachmentToUpdate is null) { return(false); } _context.Attachments.Update(attachmentToUpdate); attachmentToUpdate.Description = details.Description; attachmentToUpdate.Data = details.Data; attachmentToUpdate.Type = details.Type; return(await saveContextChanges() > 0); }
public async void UpdateAsync_GivenAttachmentExists_ReturnsTrue() { var user = new User() { Id = 1, Firstname = "Bob", Surname = "Smith", AzureUId = "foo", Mail = "*****@*****.**" }; var project = new Project() { Id = 1, Title = "Foo", Description = "Bar", Creator = user, CreatedDate = System.DateTime.UtcNow }; var attachment = new Attachment() { Id = 1, Description = "Foo", Data = "thurfh", ProjectId = 1, Project = project, Type = (int)AttachmentTypes.PDF }; context.Users.Add(user); context.Projects.Add(project); context.Attachments.Add(attachment); context.SaveChanges(); //SanityCheck Assert.Equal(1, context.Attachments.ToArray().Count()); using (var repo = new AttachmentRepository(context)) { var updatedAttachment = new AttachmentDTO() { Id = 1, Description = "Foo", Data = "thurfh", ProjectId = 1, Type = (int)AttachmentTypes.BITMAP }; var result = await repo.UpdateAsync(updatedAttachment); var expectedInDB = new Attachment() { Id = 1, Description = "Foo", Data = "thurfh", ProjectId = 1, Project = project, Type = (int)AttachmentTypes.BITMAP }; Assert.True(result); Assert.Equal(1, context.Attachments.ToArray().Count()); var attachmentinDB = context.Attachments.First(); attachmentinDB.ShouldBeEquivalentTo(expectedInDB); } }
public async void UpdateAsync_GivenAttachmentDoesNotExist_ReturnsFalse() { //SanityCheck Assert.Equal(0, context.Attachments.ToArray().Count()); using (var repo = new AttachmentRepository(context)) { var updatedAttachment = new AttachmentDTO() { Id = 1, Description = "Foo", Data = "thurfh", ProjectId = 1, Type = (int)AttachmentTypes.BITMAP }; var result = await repo.UpdateAsync(updatedAttachment); Assert.False(result); Assert.Equal(0, context.Attachments.ToArray().Count()); } }