/// <summary> /// Fixed: /// </summary> public static string Send(IContext context, string reference, long id) { var ss = SiteSettingsUtilities.GetByReference( context: context, reference: reference, referenceId: id); if (context.ContractSettings.Mail == false) { return(Error.Types.Restricted.MessageJson(context: context)); } var outgoingMailModel = new OutgoingMailModel( context: context, reference: reference, referenceId: id); var invalidMailAddress = string.Empty; var invalid = OutgoingMailValidators.OnSending( context: context, ss: ss, outgoingMailModel: outgoingMailModel, data: out invalidMailAddress); switch (invalid) { case Error.Types.None: break; case Error.Types.BadMailAddress: case Error.Types.ExternalMailAddress: return(invalid.MessageJson( context: context, data: invalidMailAddress)); default: return(invalid.MessageJson(context: context)); } var error = outgoingMailModel.Send( context: context, ss: ss); return(error.Has() ? error.MessageJson(context: context) : new OutgoingMailsResponseCollection(outgoingMailModel) .CloseDialog() .ClearFormData() .Html("#OutgoingMailDialog", string.Empty) .Val("#OutgoingMails_Title", string.Empty) .Val("#OutgoingMails_Body", string.Empty) .Prepend( "#OutgoingMailsForm", new HtmlBuilder().OutgoingMailListItem( context: context, ss: ss, outgoingMailModel: outgoingMailModel)) .Message(Messages.MailTransmissionCompletion(context: context)) .ToJson()); }
/// <summary> /// Fixed: /// </summary> public static string Send(string reference, long id) { if (!Contract.Mail()) { return(Error.Types.Restricted.MessageJson()); } var outgoingMailModel = new OutgoingMailModel(reference, id); var invalidMailAddress = string.Empty; var invalid = OutgoingMailValidators.OnSending( SiteSettingsUtilities.GetByReference(reference, id), outgoingMailModel, out invalidMailAddress); switch (invalid) { case Error.Types.None: break; case Error.Types.BadMailAddress: case Error.Types.ExternalMailAddress: return(invalid.MessageJson(invalidMailAddress)); default: return(invalid.MessageJson()); } var error = outgoingMailModel.Send(); return(error.Has() ? error.MessageJson() : new OutgoingMailsResponseCollection(outgoingMailModel) .CloseDialog() .ClearFormData() .Html("#OutgoingMailDialog", string.Empty) .Val("#OutgoingMails_Title", string.Empty) .Val("#OutgoingMails_Body", string.Empty) .Prepend("#OutgoingMailsForm", new HtmlBuilder().OutgoingMailListItem( outgoingMailModel, selector: "#ImmediatelyAfterSending" + outgoingMailModel.OutgoingMailId)) .Message(Messages.MailTransmissionCompletion()) .ToJson()); }
/// <summary> /// Fixed: /// </summary> public static System.Web.Mvc.ContentResult SendByApi(Context context, string reference, long id) { 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)); } }
/// <summary> /// Fixed: /// </summary> public static string Editor(Context context, string reference, long id) { var ss = SiteSettingsUtilities.GetByReference( context: context, reference: reference, referenceId: id); if (context.ContractSettings.Mail == false) { return(Error.Types.Restricted.MessageJson(context: context)); } if (MailAddressUtilities.Get( context: context, userId: context.UserId) == string.Empty) { return(new ResponseCollection() .CloseDialog() .Message(Messages.MailAddressHasNotSet(context: context)) .ToJson()); } var invalid = OutgoingMailValidators.OnEditing( context: context, ss: ss); switch (invalid) { case Error.Types.None: break; default: return(invalid.MessageJson(context: context)); } var outgoingMailModel = new OutgoingMailModel().Get( context: context, where : Rds.OutgoingMailsWhere().OutgoingMailId( context.Forms.Long("OutgoingMails_OutgoingMailId"))); var hb = new HtmlBuilder(); return(new ResponseCollection() .Html("#OutgoingMailDialog", hb .Div(id: "MailEditorTabsContainer", action: () => hb .Ul(id: "MailEditorTabs", action: () => hb .Li(action: () => hb .A( href: "#FieldSetMailEditor", text: Displays.Mail(context: context))) .Li(action: () => hb .A( href: "#FieldSetAddressBook", text: Displays.AddressBook(context: context)))) .FieldSet(id: "FieldSetMailEditor", action: () => hb .Form( attributes: new HtmlAttributes() .Id("OutgoingMailForm") .Action(Locations.Action( context: context, table: reference, id: id, controller: "OutgoingMails")), action: () => hb .Editor( context: context, ss: ss, outgoingMailModel: outgoingMailModel))) .FieldSet(id: "FieldSetAddressBook", action: () => hb .Form( attributes: new HtmlAttributes() .Id("OutgoingMailDestinationForm") .Action(Locations.Action( context: context, table: reference, id: id, controller: "OutgoingMails")), action: () => hb .Destinations(context: context, ss: ss))))) .Invoke("initOutgoingMailDialog") .Focus("#OutgoingMails_Body") .ToJson()); }