Пример #1
0
        public async Task <JsonResult> PublishCampaign(int?campaignId)
        {
            if (campaignId == null)
            {
                return(new JsonResult(new { success = false, Response = "", Error = "Id is null, please provide it in the request." }));
            }

            if (!_identityHelper.TryGetDistributor(out Distributor distributor, out string errorMessage))
            {
                return(new JsonResult(new { success = false, Response = "", Error = errorMessage }));
            }

            try
            {
                if (await _campaignAdapter.TryPublishCampaign(campaignId.Value, distributor))
                {
                    return(new JsonResult(new { success = true, Response = "Campaign is on the way to the advocates.", Error = "" }));
                }

                return(new JsonResult(new { success = false, Response = "", Error = "Campaing could not be sent, see logs." }));
            }
            catch (Exception exception)
            {
                return(new JsonResult(new { success = false, Response = "", Error = exception.Message }));
            }
        }