예제 #1
0
        public HttpResponseMessage UpdateObservation(ObservationVm observationVm)
        {
            if (Request.Method == HttpMethod.Options)
            {
                return new HttpResponseMessage()
                       {
                           StatusCode = HttpStatusCode.OK
                       }
            }
            ;

            if (loggedUserId == null)
            {
                //TODO: you are not logged message here
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "err niezalogowany"));
            }

            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            var observationOwnerId = _observationRepository.GetObservationOwnerId(observationVm.Id).FirstOrDefault();

            if (observationOwnerId != loggedUserId)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "err nie twoja obserwacja"));
            }

            var observationQuery = _observationRepository.GetObservation(observationVm.Id);
            var observation      = _observationVmRepository.UpdateObservationDbFromObservationVm(observationQuery.FirstOrDefault(), observationVm);

            var result = _observationRepository.UpdateObservation(observation);

            return(Request.CreateResponse(HttpStatusCode.OK,
                                          new string[] { result.ToString(), "success dane obserwacji zmienione" }));
        }