/// <summary>
        /// Fixed:
        /// </summary>
        public static string MultiUpload(Context context, long id)
        {
            var controlId = context.Forms.ControlId();
            var ss        = new ItemModel(
                context: context,
                referenceId: id).GetSite(
                context: context,
                initSiteSettings: true)
                            .SiteSettings;
            var column = ss.GetColumn(
                context: context,
                columnName: context.Forms.Data("ColumnName"));
            var attachments = context.Forms.Data("AttachmentsData").Deserialize <Attachments>();
            var invalid     = BinaryValidators.OnUploading(
                context: context,
                column: column,
                attachments: attachments);

            switch (invalid)
            {
            case Error.Types.OverLimitQuantity:
                return(Messages.ResponseOverLimitQuantity(
                           context: context,
                           data: column.LimitQuantity.ToString()).ToJson());

            case Error.Types.OverLimitSize:
                return(Messages.ResponseOverLimitSize(
                           context: context,
                           data: column.LimitSize.ToString()).ToJson());

            case Error.Types.OverTotalLimitSize:
                return(Messages.ResponseOverTotalLimitSize(
                           context: context,
                           data: column.TotalLimitSize.ToString()).ToJson());

            case Error.Types.OverTenantStorageSize:
                return(Messages.ResponseOverTenantStorageSize(
                           context: context,
                           data: context.ContractSettings.StorageSize.ToString()).ToJson());

            case Error.Types.None: break;

            default: return(invalid.MessageJson(context: context));
            }
            context.PostedFiles.ForEach(file => attachments.Add(new Attachment()
            {
                Guid        = file.Guid,
                Name        = file.FileName.Split('\\').Last(),
                Size        = file.Size,
                Extention   = file.Extension,
                ContentType = file.ContentType,
                Added       = true,
                Deleted     = false
            }));
            var hb = new HtmlBuilder();

            return(new ResponseCollection()
                   .ReplaceAll($"#{controlId}Field", new HtmlBuilder()
                               .Field(
                                   context: context,
                                   ss: ss,
                                   column: column,
                                   value: attachments.ToJson(),
                                   columnPermissionType: column
                                   .ColumnPermissionType(context: context)))
                   .SetData("#" + controlId)
                   .ToJson());
        }
Exemple #2
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string MultiUpload(Context context, long id)
        {
            var controlId = context.Forms.ControlId();
            var ss        = new ItemModel(
                context: context,
                referenceId: id).GetSite(
                context: context,
                initSiteSettings: true)
                            .SiteSettings;
            var column = ss.GetColumn(
                context: context,
                columnName: context.Forms.Data("ColumnName"));
            var attachments = context.Forms.Data("AttachmentsData").Deserialize <Attachments>();
            var invalid     = BinaryValidators.OnUploading(
                context: context,
                column: column,
                attachments: attachments);

            switch (invalid)
            {
            case Error.Types.OverLimitQuantity:
                return(Messages.ResponseOverLimitQuantity(
                           context: context,
                           data: column.LimitQuantity.ToString()).ToJson());

            case Error.Types.OverLimitSize:
                return(Messages.ResponseOverLimitSize(
                           context: context,
                           data: column.LimitSize.ToString()).ToJson());

            case Error.Types.OverTotalLimitSize:
                return(Messages.ResponseOverTotalLimitSize(
                           context: context,
                           data: column.TotalLimitSize.ToString()).ToJson());

            case Error.Types.OverTenantStorageSize:
                return(Messages.ResponseOverTenantStorageSize(
                           context: context,
                           data: context.ContractSettings.StorageSize.ToString()).ToJson());

            case Error.Types.None: break;

            default: return(invalid.MessageJson(context: context));
            }
            context.PostedFiles.ForEach(file => attachments.Add(new Attachment()
            {
                Guid        = file.Guid,
                Name        = file.FileName.Split(System.IO.Path.DirectorySeparatorChar).Last(),
                Size        = file.Size,
                Extention   = file.Extension,
                ContentType = file.ContentType,
                Added       = true,
                Deleted     = false
            }));
            var hb      = new HtmlBuilder();
            var fieldId = controlId + "Field";

            return(new ResponseCollection()
                   .ReplaceAll("#" + fieldId, new HtmlBuilder()
                               .FieldAttachments(
                                   context: context,
                                   fieldId: fieldId,
                                   controlId: controlId,
                                   columnName: column.ColumnName,
                                   fieldCss: column.FieldCss
                                   + (column.TextAlign == SiteSettings.TextAlignTypes.Right
                                ? " right-align"
                                : string.Empty),
                                   fieldDescription: column.Description,
                                   labelText: column.LabelText,
                                   value: attachments.ToJson(),
                                   readOnly: column.ColumnPermissionType(context: context)
                                   != Permissions.ColumnPermissionTypes.Update))
                   .SetData("#" + controlId)
                   .ToJson());
        }
        /// <summary>
        /// Fixed:
        /// </summary>
        public static System.Web.Mvc.ContentResult SendByApi(Context context, string reference, long id)
        {
            if (!Mime.ValidateOnApi(contentType: context.ContentType))
            {
                return(ApiResults.BadRequest(context: context));
            }
            var itemModel = new ItemModel(
                context: context,
                referenceId: id);
            var siteModel = new SiteModel(
                context: context,
                siteId: itemModel.SiteId);
            var ss = SiteSettingsUtilities.Get(
                context: context,
                siteModel: siteModel,
                referenceId: itemModel.ReferenceId);
            var outgoingMailModel = new OutgoingMailModel(
                context: context,
                reference: reference,
                referenceId: id);
            var data = context.RequestDataString.Deserialize <OutgoingMailApiModel>();

            if (data == null)
            {
                return(ApiResults.Get(ApiResponses.BadRequest(context: context)));
            }
            if (!siteModel.WithinApiLimits())
            {
                return(ApiResults.Get(ApiResponses.OverLimitApi(
                                          context: context,
                                          siteId: itemModel.SiteId,
                                          limitPerSite: Parameters.Api.LimitPerSite)));
            }
            if (data.From != null)
            {
                outgoingMailModel.From = new System.Net.Mail.MailAddress(data.From);
            }
            if (data.To != null)
            {
                outgoingMailModel.To = data.To;
            }
            if (data.Cc != null)
            {
                outgoingMailModel.Cc = data.Cc;
            }
            if (data.Bcc != null)
            {
                outgoingMailModel.Bcc = data.Bcc;
            }
            if (data.Title != null)
            {
                outgoingMailModel.Title = new Title(data.Title);
            }
            if (data.Body != null)
            {
                outgoingMailModel.Body = data.Body;
            }
            var invalid = OutgoingMailValidators.OnSending(
                context: context,
                ss: ss,
                outgoingMailModel: outgoingMailModel);

            switch (invalid.Type)
            {
            case Error.Types.None: break;

            default:
                return(ApiResults.Error(
                           context: context,
                           errorData: invalid));
            }
            var errorData = outgoingMailModel.Send(
                context: context,
                ss: ss);

            switch (errorData.Type)
            {
            case Error.Types.None:
                SiteUtilities.UpdateApiCount(context: context, ss: ss);
                return(ApiResults.Success(
                           id: id,
                           limitPerDate: Parameters.Api.LimitPerSite,
                           limitRemaining: Parameters.Api.LimitPerSite - ss.ApiCount,
                           message: Displays.MailTransmissionCompletion(
                               context: context,
                               data: outgoingMailModel.Title.DisplayValue)));

            default:
                return(ApiResults.Error(
                           context: context,
                           errorData: errorData));
            }
        }
Exemple #4
0
        /// <summary>
        /// Fixed:
        /// </summary>
        public static string UploadImage(Context context, long id)
        {
            var invalid = BinaryValidators.OnUploadingImage(context: context);

            switch (invalid)
            {
            case Error.Types.OverTenantStorageSize:
                return(Messages.ResponseOverTenantStorageSize(
                           context: context,
                           data: context.ContractSettings.StorageSize.ToString()).ToJson());

            case Error.Types.None: break;

            default: return(invalid.MessageJson(context: context));
            }
            var file       = context.PostedFiles.FirstOrDefault();
            var bin        = file.Byte();
            var columnName = context.Forms.Data("ControlId");

            if (columnName.Contains("_"))
            {
                columnName = columnName.Substring(columnName.IndexOf("_") + 1);
            }
            if (columnName.StartsWith("Comment"))
            {
                columnName = "Comments";
            }
            var ss = new ItemModel(
                context: context,
                referenceId: id)
                     .GetSite(
                context: context,
                initSiteSettings: true)
                     .SiteSettings;
            var thumbnailLimitSize = ss.GetColumn(
                context: context,
                columnName: columnName)?.ThumbnailLimitSize
                                     ?? Parameters.BinaryStorage.ThumbnailLimitSize;
            var imageData = new Libraries.Images.ImageData(
                bin,
                ss.ReferenceId,
                Libraries.Images.ImageData.Types.SiteImage);

            if (Parameters.BinaryStorage.ImageLimitSize?.ToInt() > 0)
            {
                bin = imageData.ReSizeBytes(Parameters.BinaryStorage.ImageLimitSize);
            }
            var thumbnail = thumbnailLimitSize > 0
                ? imageData.ReSizeBytes(thumbnailLimitSize)
                : null;

            if (Parameters.BinaryStorage.IsLocal())
            {
                bin.Write(System.IO.Path.Combine(
                              Directories.BinaryStorage(),
                              "Images",
                              file.Guid));
                if (thumbnailLimitSize > 0)
                {
                    thumbnail.Write(System.IO.Path.Combine(
                                        Directories.BinaryStorage(),
                                        "Images",
                                        file.Guid + "_thumbnail"));
                }
            }
            Repository.ExecuteNonQuery(
                context: context,
                statements: Rds.InsertBinaries(
                    param: Rds.BinariesParam()
                    .TenantId(context.TenantId)
                    .ReferenceId(id)
                    .Guid(file.Guid)
                    .BinaryType("Images")
                    .Title(file.FileName)
                    .Bin(bin, _using: !Parameters.BinaryStorage.IsLocal())
                    .Thumbnail(thumbnail, _using: thumbnail != null)
                    .FileName(file.FileName)
                    .Extension(file.Extension)
                    .Size(file.Size)
                    .ContentType(file.ContentType)));
            return(new ResponseCollection()
                   .InsertText(
                       "#" + context.Forms.ControlId(),
                       "![image]({0})".Params(Locations.ShowFile(
                                                  context: context,
                                                  guid: file.Guid)))
                   .ToJson());
        }