コード例 #1
0
        public async Task <ActionResult> ContactUs([FromServices] DataContext dataContext, ContactUsViewModel data)
        {
            if (ModelState.IsValid)
            {
                if (!Recaptcha.Validate(Request.Form["g-recaptcha-response"]))
                {
                    ModelState.AddModelError("ReCaptchaValid", "ReCaptcha failed please try again");
                }
                else
                {
                    ContactSubmission contactSubmission = ContactSubmission.CreateFromViewModel(data);
                    contactSubmission.EmailedTo = Settings.Emails.ToAddresses;
                    dataContext.ContactSubmissions.Add(contactSubmission);
                    dataContext.SaveChanges(currentUserName);

                    Response resp = await EmailFacade.SendAsync(contactSubmission);

                    SimpleNotifier noty = notifier();

                    if (resp.StatusCode == HttpStatusCode.Accepted)
                    {
                        noty.AddMessage(MsgTypes.Success, "Thanks for getting in contact, we will reply in due course");
                        return(Redirect("/"));
                    }
                    else
                    {
                        noty.AddMessage(MsgTypes.Warning, "Problems sending sending your message, please try again.");
                        return(View(data));
                    }
                }
            }
            return(View(data));
        }
コード例 #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var contactRecipientsOptions = new ContactRecipientsOptions
            {
                ContactRecipients = _configuration.GetValue <string>(ContactRecipientsOptions.ContactRecipientsName)
            };

            var result = await _messageService.SendMessageAsync(ContactSubmission.Message, ContactSubmission.Email,
                                                                contactRecipientsOptions.ContactRecipients.Split(","));

            if (result.IsSuccess)
            {
                ContactSubmission = new ContactSubmission();
                ModelState.Clear();
                ViewData["AlertType"]    = "success";
                ViewData["AlertMessage"] = "Your message has been sent - I'll be in touch soon!";
                return(Page());
            }
            ViewData["AlertType"]    = "danger";
            ViewData["AlertMessage"] = "Uh oh! Not sure what happened there. Please try again";
            return(Page());
        }
コード例 #3
0
        public bool ProcessContactUsSubmission(HttpContext context, ref ContactSubmission contactSubmission)
        {
            System.IO.StreamReader sr = new System.IO.StreamReader(context.Request.InputStream);

            string responseContent = sr.ReadToEnd().Trim();

            string jsonString = responseContent;

            try
            {
                JObject o = JObject.Parse(jsonString);

                JsonSerializer serializer = new JsonSerializer();
                contactSubmission = (ContactSubmission)serializer.Deserialize(new JTokenReader(o), typeof(ContactSubmission));

                return(true);
            }
            catch (Exception exp)
            {
                System.Diagnostics.Debug.WriteLine(exp);

                //submission failed
                return(false);
            }
        }
コード例 #4
0
        public bool ProcessContactUsSubmission(HttpContext context, ref ContactSubmission contactSubmission)
        {
            System.IO.StreamReader sr = new System.IO.StreamReader(context.Request.InputStream);

            string responseContent = sr.ReadToEnd().Trim();

            string jsonString = responseContent;

            try
            {
                JObject o = JObject.Parse(jsonString);

                JsonSerializer serializer = new JsonSerializer();
                contactSubmission = (ContactSubmission)serializer.Deserialize(new JTokenReader(o), typeof(ContactSubmission));

                return true;
            }
            catch (Exception exp)
            {
                System.Diagnostics.Debug.WriteLine(exp);

                //submission failed
                return false;
            }
        }
コード例 #5
0
ファイル: EmailFacade.cs プロジェクト: liammoat/FrontLineLive
        public static Task <Response> SendAsync(ContactSubmission contactSubmission)
        {
            SendGridClient      client          = new SendGridClient(Settings.Emails.SendGridKey);
            EmailAddress        from            = new EmailAddress(Settings.Emails.FromAddress);
            string              subject         = $"Message from the Frontline website - {contactSubmission.Name}";
            List <string>       emailRecipients = contactSubmission.EmailedTo.Split(',').ToList();
            List <EmailAddress> to = emailRecipients.Select(MailHelper.StringToEmailAddress).ToList();
            string              plainTextContent = "Name: " + contactSubmission.Name + "\r\nEmail: " + contactSubmission.Email + "\r\nMessage: " + contactSubmission.Message;
            SendGridMessage     msg = MailHelper.CreateSingleEmailToMultipleRecipients(from, to, subject, plainTextContent, "");

            return(client.SendEmailAsync(msg));
        }
コード例 #6
0
        public ActionResult Contact(ContactSubmission contactSubmission)
        {
            if (ModelState.IsValid)
            {
                //TODO; move submission manager out of API project to core
                SubmissionManager submissionManager = new SubmissionManager();
                bool sentOK = submissionManager.SubmitContactSubmission(contactSubmission);

                if (!sentOK)
                {
                    ViewBag.ErrorMessage = "There was a problem sending your message";
                }

                return(RedirectToAction("ContactSubmitted"));
            }

            return(View(contactSubmission));
        }
コード例 #7
0
        public ActionResult Contact(ContactSubmission contactSubmission)
        {
            if (ModelState.IsValid)
            {
                //check for spam bot by discarding submissions which populate phone field
                if (String.IsNullOrEmpty(contactSubmission.Phone))
                {
                    SubmissionManager submissionManager = new SubmissionManager();
                    bool sentOK = submissionManager.SubmitContactSubmission(contactSubmission);

                    if (!sentOK)
                    {
                        ViewBag.ErrorMessage = "There was a problem sending your message";
                    }
                }
                return RedirectToAction("ContactSubmitted");
            }

            return View(contactSubmission);
        }
コード例 #8
0
        public ActionResult Contact(ContactSubmission contactSubmission)
        {
            if (ModelState.IsValid)
            {
                //check for spam bot by discarding submissions which populate phone field
                if (String.IsNullOrEmpty(contactSubmission.Phone))
                {
                    SubmissionManager submissionManager = new SubmissionManager();
                    bool sentOK = submissionManager.SubmitContactSubmission(contactSubmission);

                    if (!sentOK)
                    {
                        ViewBag.ErrorMessage = "There was a problem sending your message";
                    }
                }
                return(RedirectToAction("ContactSubmitted"));
            }

            return(View(contactSubmission));
        }
コード例 #9
0
        /// <summary>
        /// Handle input to API
        /// </summary>
        /// <param name="context"></param>
        private void PerformInput(HttpContext context)
        {
            if (!bool.Parse(ConfigurationManager.AppSettings["EnableDataWrites"]))
            {
                OutputBadRequestMessage(context, "API is read only. Submissions not currently being accepted.");
                return;
            }
            OCM.API.InputProviders.IInputProvider inputProvider = null;

            var filter = new APIRequestParams();

            //set defaults
            filter.ParseParameters(context);

            //override ?v=2 etc if called via /api/v2/ or /api/v1
            if (APIBehaviourVersion > 0)
            {
                filter.APIVersion = APIBehaviourVersion;
            }
            if (APIBehaviourVersion >= 2)
            {
                filter.Action = DefaultAction;
            }

            if (context.Request.Url.Host.ToLower().StartsWith("api") && filter.APIVersion == null)
            {
                //API version is mandatory for api V2 onwards via api.openchargemap.* hostname
                OutputBadRequestMessage(context, "mandatory API Version not specified in request");
                return;
            }

            bool performSubmissionCompletedRedirects = false;

            //Use JSON format submission if explictly specified or by default if API v3
            if (context.Request["format"] == "json" || (String.IsNullOrEmpty(context.Request["format"]) && filter.APIVersion >= 3))
            {
                inputProvider = new InputProviders.JSONInputProvider();
            }
            else
            {
                inputProvider = new InputProviders.HTMLFormInputProvider();
                performSubmissionCompletedRedirects = true;
            }
            SubmissionManager submissionManager = new SubmissionManager();

            //attempt to determine user from api call
            User user = inputProvider.GetUserFromAPICall(context);

            if (user != null && user.IsCurrentSessionTokenValid == false)
            {
                //session token provided didn't match latest in user details, reject user details.
                context.Response.StatusCode = 401;
            }
            else
            {
                //allow contact us input whether use is authenticated or not
                if (context.Request["action"] == "contactus_submission" || filter.Action == "contact")
                {
                    ContactSubmission contactSubmission = new ContactSubmission();
                    bool processedOK = inputProvider.ProcessContactUsSubmission(context, ref contactSubmission);

                    bool resultOK = submissionManager.SendContactUsMessage(contactSubmission.Name, contactSubmission.Email, contactSubmission.Comment);
                    if (resultOK == true)
                    {
                        context.Response.Write("OK");
                    }
                    else
                    {
                        context.Response.Write("Error");
                    }
                }

                //if user not authenticated reject any other input
                if (user == null)
                {
                    context.Response.StatusCode = 401;
                    return;
                }

                //gather input variables
                if (context.Request["action"] == "cp_submission" || filter.Action == "poi")
                {
                    //gather/process data for submission
                    OCM.API.Common.Model.ChargePoint cp = new Common.Model.ChargePoint();

                    bool processedOK = inputProvider.ProcessEquipmentSubmission(context, ref cp);
                    bool submittedOK = false;

                    if (processedOK == true)
                    {
                        //perform submission

                        int submissionId = submissionManager.PerformPOISubmission(cp, user);
                        if (submissionId > -1)
                        {
                            submittedOK = true;
                        }
                    }

                    if (processedOK && submittedOK)
                    {
                        if (performSubmissionCompletedRedirects)
                        {
                            if (submittedOK)
                            {
                                context.Response.Redirect("http://openchargemap.org/submissions/complete.aspx", true);
                            }
                            else
                            {
                                context.Response.Redirect("http://openchargemap.org/submissions/error.aspx", true);
                            }
                        }
                        else
                        {
                            context.Response.StatusCode = 202;
                        }
                    }
                    else
                    {
                        if (performSubmissionCompletedRedirects)
                        {
                            context.Response.Redirect("http://openchargemap.org/submissions/error.aspx", true);
                        }
                        else
                        {
                            context.Response.StatusCode = 500;
                        }
                    }
                }

                if (context.Request["action"] == "comment_submission" || filter.Action == "comment")
                {
                    UserComment comment     = new UserComment();
                    bool        processedOK = inputProvider.ProcessUserCommentSubmission(context, ref comment);
                    if (processedOK == true)
                    {
                        //perform submission
                        int result = submissionManager.PerformSubmission(comment, user);
                        if (filter.APIVersion >= 3)
                        {
                            if (result > 0)
                            {
                                OutputSubmissionReceivedMessage(context, "OK", true);
                            }
                            else
                            {
                                OutputBadRequestMessage(context, "Failed");
                            }
                        }
                        else
                        {
                            if (result >= 0)
                            {
                                context.Response.Write("OK:" + result);
                            }
                            else
                            {
                                context.Response.Write("Error:" + result);
                            }
                        }
                    }
                    else
                    {
                        context.Response.Write("Error: Validation Failed");
                    }
                }

                if (context.Request["action"] == "mediaitem_submission" || filter.Action == "mediaitem")
                {
                    var       p        = inputProvider;// as OCM.API.InputProviders.HTMLFormInputProvider;
                    MediaItem m        = new MediaItem();
                    bool      accepted = false;
                    string    msg      = "";
                    try
                    {
                        accepted = p.ProcessMediaItemSubmission(context, ref m, user.ID);
                    }
                    catch (Exception exp)
                    {
                        msg += exp.ToString();
                    }
                    if (accepted)
                    {
                        submissionManager.PerformSubmission(m, user);
                        //OutputSubmissionReceivedMessage(context, "OK :" + m.ID, true);

                        if (filter.APIVersion >= 3)
                        {
                            OutputSubmissionReceivedMessage(context, "OK", true);
                        }
                        else
                        {
                            context.Response.Write("OK");
                        }
                    }
                    else
                    {
                        if (filter.APIVersion >= 3)
                        {
                            OutputBadRequestMessage(context, "Failed");
                        }
                        else
                        {
                            context.Response.Write("Error");
                        }
                    }
                }
            }
        }
コード例 #10
0
 public bool ProcessContactUsSubmission(HttpContext context, ref ContactSubmission contactSubmission)
 {
     //not implemented
     return(false);
 }
コード例 #11
0
        /// <summary>
        /// Handle input to API
        /// </summary>
        /// <param name="context"></param>
        private void PerformInput(HttpContext context)
        {
            OCM.API.InputProviders.IInputProvider inputProvider = null;
            bool performSubmissionCompletedRedirects            = false;

            if (context.Request["format"] == "json")
            {
                inputProvider = new InputProviders.JSONInputProvider();
            }
            else
            {
                inputProvider = new InputProviders.HTMLFormInputProvider();
                performSubmissionCompletedRedirects = true;
            }
            SubmissionManager submissionManager = new SubmissionManager();

            //attempt to determine user from api call
            User user = inputProvider.GetUserFromAPICall(context);

            if (user != null && user.IsCurrentSessionTokenValid == false)
            {
                //session token provided didn't match latest in user details, reject user details.
                context.Response.StatusCode = 401;
            }
            else
            {
                //gather input variables
                if (context.Request["action"] == "cp_submission")
                {
                    //gather/process data for submission
                    OCM.API.Common.Model.ChargePoint cp = new Common.Model.ChargePoint();

                    bool processedOK = inputProvider.ProcessEquipmentSubmission(context, ref cp);
                    bool submittedOK = false;

                    if (processedOK == true)
                    {
                        //perform submission

                        int submissionId = submissionManager.PerformPOISubmission(cp, user);
                        if (submissionId > -1)
                        {
                            submittedOK = true;
                        }
                    }

                    if (processedOK && submittedOK)
                    {
                        if (performSubmissionCompletedRedirects)
                        {
                            if (submittedOK)
                            {
                                context.Response.Redirect("http://openchargemap.org/submissions/complete.aspx", true);
                            }
                            else
                            {
                                context.Response.Redirect("http://openchargemap.org/submissions/error.aspx", true);
                            }
                        }
                        else
                        {
                            context.Response.StatusCode = 202;
                            //context.Response.AddHeader("Access-Control-Allow-Origin", "*");
                        }
                    }
                    else
                    {
                        if (performSubmissionCompletedRedirects)
                        {
                            context.Response.Redirect("http://openchargemap.org/submissions/error.aspx", true);
                        }
                        else
                        {
                            context.Response.StatusCode = 500;
                            //context.Response.AddHeader("Access-Control-Allow-Origin", "*");
                        }
                    }
                }

                if (context.Request["action"] == "comment_submission")
                {
                    UserComment comment     = new UserComment();
                    bool        processedOK = inputProvider.ProcessUserCommentSubmission(context, ref comment);
                    if (processedOK == true)
                    {
                        //perform submission
                        int result = submissionManager.PerformSubmission(comment, user);

                        if (result >= 0)
                        {
                            context.Response.Write("OK:" + result);
                        }
                        else
                        {
                            context.Response.Write("Error:" + result);
                        }
                    }
                    else
                    {
                        context.Response.Write("Error: Validation Failed");
                    }
                }

                if (context.Request["action"] == "contactus_submission")
                {
                    ContactSubmission contactSubmission = new ContactSubmission();
                    bool processedOK = inputProvider.ProcessContactUsSubmission(context, ref contactSubmission);

                    bool resultOK = submissionManager.SendContactUsMessage(contactSubmission.Name, contactSubmission.Email, contactSubmission.Comment);
                    if (resultOK == true)
                    {
                        context.Response.Write("OK");
                    }
                    else
                    {
                        context.Response.Write("Error");
                    }
                }

                if (context.Request["action"] == "mediaitem_submission")
                {
                    var       p        = inputProvider as OCM.API.InputProviders.HTMLFormInputProvider;
                    MediaItem m        = new MediaItem();
                    bool      accepted = false;
                    string    msg      = "";
                    try
                    {
                        accepted = p.ProcessMediaItemSubmission(context, ref m, user.ID);
                    }
                    catch (Exception exp)
                    {
                        msg += exp.ToString();
                    }
                    if (accepted)
                    {
                        submissionManager.PerformSubmission(m, user);
                        //OutputSubmissionReceivedMessage(context, "OK :" + m.ID, true);
                        context.Response.Write("OK");
                    }
                    else
                    {
                        //OutputBadRequestMessage(context, "Error, could not accept submission: " + msg);
                        context.Response.Write("Error");
                    }
                }
            }
        }
コード例 #12
0
ファイル: service.ashx.cs プロジェクト: solarpete/ocm-system
        /// <summary>
        /// Handle input to API
        /// </summary>
        /// <param name="context"></param>
        private void PerformInput(HttpContext context)
        {
            OCM.API.InputProviders.IInputProvider inputProvider = null;
            bool performSubmissionCompletedRedirects = false;

            if (context.Request["format"] == "json")
            {
                inputProvider = new InputProviders.JSONInputProvider();
            }
            else
            {
                inputProvider = new InputProviders.HTMLFormInputProvider();
                performSubmissionCompletedRedirects = true;
            }
            SubmissionManager submissionManager = new SubmissionManager();

            //attempt to determine user from api call
            User user = inputProvider.GetUserFromAPICall(context);

            if (user != null && user.IsCurrentSessionTokenValid == false)
            {
                //session token provided didn't match latest in user details, reject user details.
                context.Response.StatusCode = 401;
            }
            else
            {
                //gather input variables
                if (context.Request["action"] == "cp_submission")
                {
                    //gather/process data for submission
                    OCM.API.Common.Model.ChargePoint cp = new Common.Model.ChargePoint();

                    bool processedOK = inputProvider.ProcessEquipmentSubmission(context, ref cp);
                    bool submittedOK = false;

                    if (processedOK == true)
                    {
                        //perform submission

                        int submissionId = submissionManager.PerformPOISubmission(cp, user);
                        if (submissionId > -1) submittedOK = true;
                    }

                    if (processedOK && submittedOK)
                    {
                        if (performSubmissionCompletedRedirects)
                        {
                            if (submittedOK)
                            {
                                context.Response.Redirect("http://openchargemap.org/submissions/complete.aspx", true);
                            }
                            else
                            {
                                context.Response.Redirect("http://openchargemap.org/submissions/error.aspx", true);
                            }
                        }
                        else
                        {
                            context.Response.StatusCode = 202;
                            //context.Response.AddHeader("Access-Control-Allow-Origin", "*");
                        }
                    }
                    else
                    {
                        if (performSubmissionCompletedRedirects)
                        {
                            context.Response.Redirect("http://openchargemap.org/submissions/error.aspx", true);
                        }
                        else
                        {
                            context.Response.StatusCode = 500;
                            //context.Response.AddHeader("Access-Control-Allow-Origin", "*");
                        }
                    }
                }

                if (context.Request["action"] == "comment_submission")
                {
                    UserComment comment = new UserComment();
                    bool processedOK = inputProvider.ProcessUserCommentSubmission(context, ref comment);
                    if (processedOK == true)
                    {
                        //perform submission
                        int result = submissionManager.PerformSubmission(comment, user);

                        if (result >= 0)
                        {
                            context.Response.Write("OK:" + result);
                        }
                        else
                        {
                            context.Response.Write("Error:" + result);
                        }
                    }
                    else
                    {
                        context.Response.Write("Error: Validation Failed");
                    }
                }

                if (context.Request["action"] == "contactus_submission")
                {
                    ContactSubmission contactSubmission = new ContactSubmission();
                    bool processedOK = inputProvider.ProcessContactUsSubmission(context, ref contactSubmission);

                    bool resultOK = submissionManager.SendContactUsMessage(contactSubmission.Name, contactSubmission.Email, contactSubmission.Comment);
                    if (resultOK == true)
                    {
                        context.Response.Write("OK");
                    }
                    else
                    {
                        context.Response.Write("Error");
                    }
                }

                if (context.Request["action"] == "mediaitem_submission")
                {
                    var p = inputProvider as OCM.API.InputProviders.HTMLFormInputProvider;
                    MediaItem m = new MediaItem();
                    bool accepted = false;
                    string msg = "";
                    try
                    {
                        accepted = p.ProcessMediaItemSubmission(context, ref m, user.ID);
                    }
                    catch (Exception exp)
                    {
                        msg += exp.ToString();
                    }
                    if (accepted)
                    {
                        submissionManager.PerformSubmission(m, user);
                        //OutputSubmissionReceivedMessage(context, "OK :" + m.ID, true);
                        context.Response.Write("OK");
                    }
                    else
                    {
                        //OutputBadRequestMessage(context, "Error, could not accept submission: " + msg);
                        context.Response.Write("Error");
                    }
                }
            }
        }
コード例 #13
0
 public bool SubmitContactSubmission(ContactSubmission contactSubmission)
 {
     return(SendContactUsMessage(contactSubmission.Name, contactSubmission.Email, contactSubmission.Comment));
 }
コード例 #14
0
        /// <summary>
        /// Handle input to API
        /// </summary>
        /// <param name="context"></param>
        private async Task <bool> PerformInput(HttpContext context)
        {
            if (!_settings.EnableDataWrites)
            {
                await OutputBadRequestMessage(context, "API is read only. Submissions not currently being accepted.");

                return(true);
            }

            OCM.API.InputProviders.IInputProvider inputProvider = null;

            var filter = new APIRequestParams();

            //set defaults
            var paramList = new NullSafeDictionary <string, string>();

            foreach (var k in context.Request.Query.Keys)
            {
                paramList.Add(k.ToLower(), context.Request.Query[k]);
            }

            filter.ParseParameters(filter, paramList);

            if (string.IsNullOrEmpty(filter.APIKey))
            {
                if (context.Request.Headers.ContainsKey("X-API-Key"))
                {
                    filter.APIKey = context.Request.Headers["X-API-Key"];
                }
            }

            //override ?v=2 etc if called via /api/v2/ or /api/v1
            if (APIBehaviourVersion > 0)
            {
                filter.APIVersion = APIBehaviourVersion;
            }
            if (APIBehaviourVersion >= 2)
            {
                filter.Action = DefaultAction;
            }

            if (context.Request.GetUri().Host.ToLower().StartsWith("api") && filter.APIVersion == null)
            {
                //API version is mandatory for api V2 onwards via api.openchargemap.* hostname
                await OutputBadRequestMessage(context, "mandatory API Version not specified in request");

                return(true);
            }

            bool performSubmissionCompletedRedirects = false;

            //Use JSON format submission if explictly specified or by default if API v3
            if (context.Request.Query["format"] == "json" || (String.IsNullOrEmpty(context.Request.Query["format"]) && filter.APIVersion >= 3))
            {
                inputProvider = new InputProviders.JSONInputProvider();
            }
            else
            {
                inputProvider = new InputProviders.HTMLFormInputProvider();
                performSubmissionCompletedRedirects = true;
            }

            SubmissionManager submissionManager = new SubmissionManager();

            //attempt to determine user from api call
            User user = inputProvider.GetUserFromAPICall(context, filter.APIKey);

            if (user != null && user.IsCurrentSessionTokenValid == false)
            {
                //session token provided didn't match latest in user details, reject user details.
                context.Response.StatusCode = 401;
            }
            else
            {
                //allow contact us input whether use is authenticated or not
                if (context.Request.Query["action"] == "contactus_submission" || filter.Action == "contact")
                {
                    ContactSubmission contactSubmission = new ContactSubmission();
                    bool processedOK = inputProvider.ProcessContactUsSubmission(context, ref contactSubmission);

                    bool resultOK = submissionManager.SendContactUsMessage(contactSubmission.Name, contactSubmission.Email, contactSubmission.Comment);
                    if (resultOK == true)
                    {
                        await context.Response.WriteAsync("OK");
                    }
                    else
                    {
                        await context.Response.WriteAsync("Error");
                    }
                    return(true);
                }

                //if user not authenticated reject any other input
                if (user == null)
                {
                    context.Response.StatusCode = 401;
                    return(true);
                }

                //gather input variables
                if (context.Request.Query["action"] == "cp_submission" || filter.Action == "poi")
                {
                    //gather/process data for submission
                    var processingResult = await inputProvider.ProcessEquipmentSubmission(context);

                    ValidationResult submissionResult = new ValidationResult {
                        IsValid = false
                    };

                    if (processingResult.IsValid)
                    {
                        //perform submission
                        submissionResult = await submissionManager.PerformPOISubmission((ChargePoint)processingResult.Item, user);
                    }

                    if (processingResult.IsValid && submissionResult.IsValid)
                    {
                        if (performSubmissionCompletedRedirects)
                        {
                            context.Response.Redirect("http://openchargemap.org/submissions/complete.aspx", true);
                        }
                        else
                        {
                            context.Response.StatusCode = 202;
                        }
                        return(true);
                    }
                    else
                    {
                        // validation or submission failed
                        if (performSubmissionCompletedRedirects)
                        {
                            context.Response.Redirect("http://openchargemap.org/submissions/error.aspx", true);
                        }
                        else
                        {
                            context.Response.StatusCode = 400;
                            await context.Response.WriteAsync(processingResult.IsValid?submissionResult.Message : processingResult.Message);
                        }
                        return(true);
                    }
                }

                if (context.Request.Query["action"] == "cp_batch_submission")
                {
                    var    sr          = new System.IO.StreamReader(context.Request.Body);
                    string contentJson = sr.ReadToEnd().Trim();

                    var list = JsonConvert.DeserializeObject <List <ChargePoint> >(contentJson);
                    foreach (var cp in list)
                    {
                        var validationResult = POIManager.IsValid(cp);

                        ValidationResult submissionResult = new ValidationResult {
                            IsValid = false
                        };

                        if (validationResult.IsValid)
                        {
                            //perform submission
                            submissionResult = await submissionManager.PerformPOISubmission(cp, user, performCacheRefresh : false);
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("Invalid POI: " + cp.ID);
                        }
                    }

                    // refresh cache
                    var cacheTask = System.Threading.Tasks.Task.Run(async() =>
                    {
                        return(await Core.Data.CacheManager.RefreshCachedData());
                    });
                    cacheTask.Wait();

                    context.Response.StatusCode = 202;
                    return(true);
                }

                if (context.Request.Query["action"] == "comment_submission" || filter.Action == "comment")
                {
                    UserComment comment     = new UserComment();
                    bool        processedOK = await inputProvider.ProcessUserCommentSubmission(context, comment);

                    if (processedOK == true)
                    {
                        //perform submission
                        int result = await submissionManager.PerformSubmission(comment, user);

                        if (filter.APIVersion >= 3)
                        {
                            if (result > 0)
                            {
                                await OutputSubmissionReceivedMessage(context, "OK", true);
                            }
                            else
                            {
                                await OutputBadRequestMessage(context, "Failed");
                            }
                        }
                        else
                        {
                            if (result >= 0)
                            {
                                await context.Response.WriteAsync("OK:" + result);
                            }
                            else
                            {
                                await context.Response.WriteAsync("Error:" + result);
                            }
                        }
                    }
                    else
                    {
                        await context.Response.WriteAsync("Error: Validation Failed");
                    }

                    return(true);
                }

                if (context.Request.Query["action"] == "mediaitem_submission" || filter.Action == "mediaitem")
                {
                    var       p        = inputProvider;
                    MediaItem m        = new MediaItem();
                    bool      accepted = false;
                    string    msg      = "";

                    try
                    {
                        var tempPath = Path.Join(System.IO.Path.GetTempPath(), "_ocm");
                        if (!System.IO.Directory.Exists(tempPath))
                        {
                            System.IO.Directory.CreateDirectory(tempPath);
                        }

                        accepted = await p.ProcessMediaItemSubmission(tempPath, context, m, user.ID);
                    }
                    catch (Exception exp)
                    {
                        msg += exp.ToString();
                    }

                    if (accepted)
                    {
                        submissionManager.PerformSubmission(m, user);
                        //OutputSubmissionReceivedMessage(context, "OK :" + m.ID, true);

                        if (filter.APIVersion >= 3)
                        {
                            await OutputSubmissionReceivedMessage(context, "OK", true);
                        }
                        else
                        {
                            await context.Response.WriteAsync("OK");
                        }
                    }
                    else
                    {
                        if (filter.APIVersion >= 3)
                        {
                            await OutputBadRequestMessage(context, "Failed");
                        }
                        else
                        {
                            await context.Response.WriteAsync("Error");
                        }
                    }
                    return(true);
                }
            }

            // submission was not handled
            return(false);
        }
コード例 #15
0
 public bool ProcessContactUsSubmission(HttpContext context, ref ContactSubmission contactSubmission)
 {
     //not implemented
     return false;
 }
コード例 #16
0
 public bool SubmitContactSubmission(ContactSubmission contactSubmission)
 {
     return SendContactUsMessage(contactSubmission.Name, contactSubmission.Email, contactSubmission.Comment);
 }