public void Put(int id, MissionView view)
 {
     view.id = id;
     var model = view.getModel(repo);
     model.updated = DateTime.UtcNow;
     repo.update(model);
 }
        public HttpResponseMessage Post(MissionView view)
        {
            var model = view.getModel(repo);
            model.created = DateTime.UtcNow;
            model.updated = DateTime.UtcNow;
            model.enabled = true;
            model.fakeId = Guid.NewGuid();
            model = repo.createMission(model);
            view = new MissionView(model);

            var response = Request.CreateResponse<MissionView>(HttpStatusCode.Created, view);
            string uri = Url.Route(null, new { id = view.id });
            response.Headers.Location = new Uri(Request.RequestUri, uri);
            return response;
        }
        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;
        }
 public HttpResponseMessage Get(int id)
 {
     var model = repo.getMission(id);
     if (model == null)
     {
         return Request.CreateResponse(HttpStatusCode.NotFound);
     }
     else
     {
         var view = new MissionView(model);
         return Request.CreateResponse(HttpStatusCode.OK, view);
     }
 }