public HttpResponseMessage PostElk(TextMessageView view)
        {
            var respons = ElkTextMessage.send(view);

            var model = view.getModel();

            model.created = DateTime.UtcNow;

            if (respons.StatusCode == HttpStatusCode.OK)
            {
                var body = respons.DynamicBody;

                model.apiId = body.id;
                model.error = false;

                model = repo.createTextMessage(model);

                return(Request.CreateResponse(respons.StatusCode, model));
            }
            else
            {
                var message = respons.RawText.Replace("\"", String.Empty);

                model.error        = true;
                model.errorMessage = message;
                model = repo.createTextMessage(model);

                return(Request.CreateResponse(respons.StatusCode, message));
            }
        }
예제 #2
0
        public HttpResponseMessage PostAndContact(MissionView view)
        {
            var response = this.Post(view);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                return(response);
            }

            var employees = repo.getAllEmployees()
                            .Where(e => e.enabled == true)
                            .Where(e => view.categoryIds.All(c => e.categories.Select(c2 => c2.id).Contains(c)));

            var models = new List <TextMessageView>();

            foreach (var employee in employees)
            {
                var messageView = new TextMessageView()
                {
                    from    = "Jobsystems",
                    message = "Hej " + employee.firstName + "!" +
                              "\r\nVi har ett nytt uppdrag till dig:" +
                              "\r\n" +
                              "\r\nDatum: " + view.date.Split('T')[0] +
                              "\r\nTid: " + view.date.Split('T')[1].Substring(0, 5) +
                              "\r\nPlats: " + view.address.street + ", " + view.address.postalCode + " " + view.address.postalTown +
                              "\r\n" +
                              "\r\nLåter detta intressant?",
                    to = employee.phoneNumber,
                };

                var elkResponse = ElkTextMessage.send(messageView);

                var model = messageView.getModel();
                model.created = DateTime.UtcNow;

                if (elkResponse.StatusCode == HttpStatusCode.OK)
                {
                    var body = elkResponse.DynamicBody;

                    model.apiId = body.id;
                    model.error = false;

                    model = repo.createTextMessage(model);
                }
                else
                {
                    var message = elkResponse.RawText.Replace("\"", String.Empty);

                    model.error        = true;
                    model.errorMessage = message;
                    model = repo.createTextMessage(model);
                }

                models.Add(new TextMessageView(model));
            }

            return(response);
        }