/// <summary> /// 上传附件 /// </summary> /// <param name="attachment">附件信息</param> /// <returns>上传成功或失败</returns> public bool Upload(AttachmentModel attachment) { if (attachment == null || attachment.Content == null || string.IsNullOrEmpty(attachment.EntityType) || attachment.EntityId < 1) { throw new InvalidOperationException("附件信息无效。"); } using (var dbContext = new MissionskyOAEntities()) { dbContext.Attachments.Add(attachment.ToEntity()); dbContext.SaveChanges(); return(true); } }
/// <summary> /// Save an attachment /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <ResultModel <AttachmentModel> > SaveAttachment(AttachmentModel model) { ResultModel <AttachmentModel> result = new ResultModel <AttachmentModel>(); Attachment entity = model.ToEntity(); if (entity.Id <= 0) { entity.AddedDate = DateTime.Now; } entity.Task = null; entity.User = null; UnitOfWork.AttachRepository.Add(entity); int iResult = await UnitOfWork.CommitAsync(); if (iResult > 0) { result.Status = ActionStatus.Ok; result.Data = entity.ToModel(); } return(result); }