Esempio n. 1
0
        public HttpResponseMessage AddObservation(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 observation = _observationVmRepository.CreateNewObservationFromObservationVm(observationVm);

            var result = _observationRepository.AddObservation(observation);

            return(Request.CreateResponse(HttpStatusCode.OK,
                                          new string[] { result.ToString(), "success nowa Obserwacja dodana" }));
        }
Esempio n. 2
0
        public HttpResponseMessage GetObservation(int id)
        {
            if (loggedUserId == null)
            {
                //TODO: you are not logged message here
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "err niezalogowany"));
            }

            var observation = _observationRepository.GetObservation(id).FirstOrDefault();

            if (observation == null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "err Observation nie istenieje"));
            }

            var result = new ObservationVm(observation);

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Esempio n. 3
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" }));
        }
        public Observation CreateNewObservationFromObservationVm(ObservationVm observationVm)
        {
            Observation observation = UpdateObservationDbFromObservationVm(new Observation(), observationVm);

            return(observation);
        }
        public Observation UpdateObservationDbFromObservationVm(Observation observation, ObservationVm observationVm)
        {
            observation.CycleId       = _observationRepository.UpdateCycleId(observationVm.ParentChartId, observationVm.NumberOfParentCycleInChart);
            observation.NumberInCycle = observationVm.NumberInCycle;
            observation.Marker        = _observationRepository.GetMarkerByValue(observationVm.Marker).FirstOrDefault();
            observation.PeakDayNumber = observationVm.PeakDayNumber;
            observation.Date          = observationVm.Date;
            observation.Letter        = _observationRepository.GetLetterByValue(observationVm.Letter).FirstOrDefault();
            observation.IsB           = observationVm.IsB;
            observation.NumTimes      = _observationRepository.GetNumTimesByValue(observationVm.NumTimes).FirstOrDefault();
            observation.Cipher        = _observationRepository.GetCipherByValue(observationVm.Cipher).FirstOrDefault();
            observation.CipherCd      = _observationRepository.GetCipherCdByValue(observationVm.CipherCd).FirstOrDefault();
            //comments. notes, pictures
            //public int? CommentId { get; set; }
            //public virtual IList<Comment> Comments { get; set; }

            foreach (var item in observationVm.Notes)
            {
                ObservationNote note = new ObservationNote()
                {
                    Id            = item.Id,
                    IsImportant   = item.IsImportant,
                    Content       = item.Content,
                    ObservationId = item.ObservationId
                };

                if (item.Content != "")
                {
                    if (item.Id != 0)
                    {
                        _observationRepository.UpdateNote(note);
                    }
                    else
                    {
                        _observationRepository.AddNote(note);
                    }
                }
                else if (item.Id != 0)
                {
                    _observationRepository.DeleteNote(note);
                }
            }

            return(observation);
        }