Esempio n. 1
0
 /// <summary>
 /// Fixed:
 /// </summary>
 public static System.Web.Mvc.ContentResult ApiDonwload(Context context, string guid)
 {
     if (!context.ContractSettings.Attachments())
     {
         return(null);
     }
     return(FileContentResults.DownloadByApi(context: context, guid: guid));
 }
 /// <summary>
 /// Fixed:
 /// </summary>
 public static System.Web.Mvc.FileContentResult DownloadTemp(Context context, string guid)
 {
     if (!context.ContractSettings.Attachments())
     {
         return(null);
     }
     return(FileContentResults.DownloadTemp(guid));
 }
Esempio n. 3
0
 /// <summary>
 /// Fixed:
 /// </summary>
 public static ResponseFile DownloadTemp(Context context, string guid)
 {
     if (!context.ContractSettings.Attachments())
     {
         return(null);
     }
     return(FileContentResults.DownloadTemp(guid.ToUpper()));
 }
Esempio n. 4
0
 /// <summary>
 /// Fixed:
 /// </summary>
 public static System.Web.Mvc.FileContentResult DownloadTemp(string guid)
 {
     if (!Contract.Attachments())
     {
         return(null);
     }
     return(FileContentResults.DownloadTemp(guid));
 }
Esempio n. 5
0
 /// <summary>
 /// Fixed:
 /// </summary>
 public static System.Web.Mvc.FileContentResult Donwload(Context context, string guid)
 {
     if (!Contract.Attachments(context: context))
     {
         return(null);
     }
     return(FileContentResults.Download(context: context, guid: guid));
 }
Esempio n. 6
0
 /// <summary>
 /// Fixed:
 /// </summary>
 public static Microsoft.AspNetCore.Mvc.FileContentResult DownloadTemp(string guid)
 {
     if (!Contract.Attachments())
     {
         return(null);
     }
     return(FileContentResults.DownloadTemp(guid));
 }
Esempio n. 7
0
 /// <summary>
 /// Fixed:
 /// </summary>
 public static System.Web.Mvc.ContentResult ApiDonwload(Context context, string guid)
 {
     if (!Mime.ValidateOnApi(contentType: context.ContentType))
     {
         return(ApiResults.BadRequest(context: context));
     }
     if (!context.ContractSettings.Attachments())
     {
         return(null);
     }
     return(FileContentResults.DownloadByApi(context: context, guid: guid.ToUpper()));
 }
Esempio n. 8
0
 internal void AttachmentAction(Context context, Column column, Attachments oldAttachments)
 {
     switch (Action)
     {
         case "Linked":
             FileContentResults.LinkBinary(
                 context: context,
                 attachment: this,
                 column: column);
             BinaryUtilities.OverwriteSameFileName(
                 attachments: oldAttachments,
                 fileName: Name);
             break;
         default:
             break;
     }
 }
        public ContentResult Upload(Context context, string guid)
        {
            var log = new SysLogModel(context: context);

            if (!context.Authenticated)
            {
                return(ApiResults.Unauthorized(context: context));
            }
            if (context.PostedFiles == null || context.PostedFiles.Count == 0)
            {
                return(ApiResults.BadRequest(context: context));
            }
            var    postedFile = context.PostedFiles[0];
            string filePath   = string.Empty;

            try
            {
                if (!guid.IsNullOrEmpty())
                {
                    guid = guid.ToUpper();
                    var referenceId = FileContentResults.GetReferenceId(
                        context: context,
                        guid: guid);
                    if (referenceId == 0)
                    {
                        return(ApiResults.NotFound(context: context));
                    }
                    var targetGuid = context.QueryStrings.Bool("overwrite")
                        ? guid
                        : Strings.NewGuid();
                    filePath = SaveFileToTemp(
                        guid: targetGuid,
                        file: postedFile);
                    context.ApiRequestBody = CreateAttachmentsHashJson(
                        context: context,
                        guidParam: $"{guid},{targetGuid}",
                        referenceId: referenceId,
                        file: postedFile);
                    var response = new ItemModel(
                        context: context,
                        referenceId: referenceId)
                                   .UpdateByApi(context: context);
                    log.Finish(
                        context: context,
                        responseSize: response?.Content?.Length ?? 0);
                    return(response);
                }
                else
                {
                    if (context.QueryStrings.Long("id") == 0 ||
                        !Mime.ValidateOnApi(contentType: context.ContentType))
                    {
                        return(ApiResults.BadRequest(context: context));
                    }
                    var targetGuid = Strings.NewGuid();
                    filePath = SaveFileToTemp(
                        guid: targetGuid,
                        file: postedFile);
                    var attachment = Attachment(
                        guidParam: targetGuid,
                        referenceId: context.QueryStrings.Long("id"),
                        file: postedFile);
                    var response = attachment.Create(context: context);
                    log.Finish(
                        context: context,
                        responseSize: response?.Content?.Length ?? 0);
                    return(response);
                }
            }
            finally
            {
                Files.DeleteFile(filePath);
            }
        }