public async Task <AttachmentResponseModel> GetAttachmentDownloadDataAsync(Cipher cipher, string attachmentId) { var attachments = cipher?.GetAttachments() ?? new Dictionary <string, CipherAttachment.MetaData>(); if (!attachments.ContainsKey(attachmentId) || attachments[attachmentId].Validated) { throw new NotFoundException(); } var data = attachments[attachmentId]; var response = new AttachmentResponseModel(attachmentId, data, cipher, _globalSettings) { Url = await _attachmentStorageService.GetAttachmentDownloadUrlAsync(cipher, data) }; return(response); }
public async Task <AttachmentResponseModel> GetAttachmentData(string id, string attachmentId) { var userId = _userService.GetProperUserId(User).Value; var cipher = await _cipherRepository.GetByIdAsync(new Guid(id), userId); var attachments = cipher.GetAttachments(); if (!attachments.ContainsKey(attachmentId)) { throw new NotFoundException(); } var data = attachments[attachmentId]; var response = new AttachmentResponseModel(attachmentId, data, cipher, _globalSettings) { Url = await _attachmentStorageService.GetAttachmentDownloadUrlAsync(cipher, data) }; return(response); }
public async Task <IActionResult> Attachment([FromBody] AttachmentRequestModel model) { var response = new APIResponse <AttachmentResponseModel>() { Success = true }; AttachmentResponseModel responseModel = new AttachmentResponseModel(); try { if (ModelState.IsValid) { var check = await _accountCtx.Citations.ForAccount(CommonAccount.Id).AsNoTracking().AnyAsync(x => x.Id == model.CitationId); if (check) { foreach (var attachment in model.Attachments) { // put dude in the database Attachment attach = new Attachment() { AccountId = CommonAccount.Id, ContentLength = attachment.Length, MimeType = attachment.MimeType, FileName = attachment.FileName, Description = attachment.Description, Key = attachment.Key, Duration = attachment.Duration, AttachmentType = attachment.FileName.GetAttachmentType(), CreateUserId = User.GetJWTLoggedInUserId().Value, UpdateUserId = User.GetJWTLoggedInUserId().Value }; var citationAttach = await SaveAttachments(attach, model.CitationId); var obj = Mapper.Map <AttachmentResponse>(citationAttach); responseModel.Response.Add(obj); } //Create Receipt await _citationSvc.CreateCitationReceipt(CommonAccount.Id, model.CitationId, model.DeviceReceipt, model.DevicePublicKey, User.GetJWTLoggedInUserId().Value); response.Data = responseModel; } else { response.Success = false; response.Errors.Add(new Error { Code = 0, Message = "Invalid Citation Id " }); } } else { response.Success = false; response.Errors.AddRange(ModelState.ToErrors()); } } catch (Exception ex) { response.Success = false; response.Message = ex.Message; } return(Ok(response)); }