Esempio n. 1
0
        public HttpResponseMessage AddChart(ChartVm chartVm)
        {
            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));
            }

            Chart chart  = _chartVmRepository.CreateNewChartFromChartVm(loggedUserId, chartVm);
            var   result = _chartRepository.AddChart(chart);

            //TODO: what if chart with this name already exists??
            return(Request.CreateResponse(HttpStatusCode.Created,
                                          new string[] { result.ToString(), "success nowa karta dodana" }));
        }
        public Chart CreateNewChartFromChartVm(string loggedUserId, ChartVm chartVm)
        {
            var result = UpdateChartFromChartVm(new Chart(), chartVm);

            result.UserId = loggedUserId;
            return(result);
        }
Esempio n. 3
0
        public ActionResult Index(int Id)
        {
            ChartVm chartVm = new ChartVm();
            var     patient = GetPatient(Id);

            chartVm.PatientId = patient.Id;

            chartVm.PatientName = patient.FirstName + " " + patient.Surname;
            return(View(chartVm));
        }
Esempio n. 4
0
        public HttpResponseMessage UpdateChart(ChartVm chartVm)
        {
            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 chartQuery  = _chartRepository.GetChart(chartVm.Id);
            var chartUserId = chartQuery.Select(x => x.UserId).FirstOrDefault();

            if (chartUserId != loggedUserId)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "err nie twoj chart"));
            }

            var chart = _chartVmRepository.UpdateChartFromChartVm(chartQuery.FirstOrDefault(), chartVm);

            //TODO: what if chart with this name already exists??
            var result = _chartRepository.UpdateChart(chart);

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

            var chart = _chartRepository.GetChart(id).FirstOrDefault();

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

            if (chart.UserId != loggedUserId)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "err nie twoj chart"));
            }

            var result = new ChartVm(chart);

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
 public Chart UpdateChartFromChartVm(Chart chart, ChartVm chartVm)
 {
     chart.Title = chartVm.Title;
     chart.Note  = chartVm.Note;
     return(chart);
 }