public ActionResult GetAttachmentId(AttachmentKeyModel model) { try { model.CheckArgumentIsNull(nameof(model)); model.FieldName.CheckArgumentIsNullOrEmpty(nameof(model.FieldName)); model.EntityName.CheckArgumentIsNullOrEmpty(nameof(model.EntityName)); if (model.EntityId.HasValue()) { var attachmentId = attachmentBusiness.GetAttachmentId(model);//check read permission if (attachmentId == null) { return(Ok(attachmentBusiness.CreateAttachment(model)));//check create permission } return(Ok(attachmentId)); } else { var token = tokenProvider.GetAttachmentToken(); if (!token.HasValue()) { token = tokenProvider.SetAttachmentToken(); } var tempAttachmentKeyModel = new TemporaryAttachmentKeyModel { EntityName = model.EntityName, FieldName = model.FieldName, Token = token }; return(Ok(attachmentBusiness.CreateAttachmentTemporarily(tempAttachmentKeyModel)));//check create permission } } catch (Exception) { return(BadRequest()); } }
/// <summary> /// connect a temporarty atttachment to an actual entity id /// </summary> /// <param name="entityName"></param> /// <param name="fieldName"></param> /// <param name="token"></param> /// <param name="entityId"></param> /// <param name=""></param> /// <returns>attachmentId</returns> public int SetEntityId(string entityName, string fieldName, string entityId) { var token = tokenProvider.GetAttachmentToken(); if (!token.HasValue()) { throw new NullReferenceException("Attachment token don't have value"); } return(attachmentBusiness.PreserveAttachment(new PreserveAttachmentModel { EntityName = entityName, FieldName = fieldName, Token = token, EntityId = entityId })); }