public void TestPutPatientError()
        {
            var Controller = new PatientsController();

            Controller.Request       = new HttpRequestMessage();
            Controller.Configuration = new HttpConfiguration();

            PatientDetailDto patientdto = new PatientDetailDto()
            {
                Id               = 201,
                Name             = "Suresh Kumar",
                Age              = "50 years 0 months",
                Gender           = "Male",
                Weight           = 90,
                ConsultingDoctor = 102,
                DOB              = new DateTime(1967, 8, 12),
                Disease          = "Diarrhoea",
                Contact          = "9983464423",
                RegistrationFee  = 1000,
                LastVisit        = new DateTime(),
                StatusFlag       = 0
            };


            var response = Controller.PutPatient(101, patientdto);

            Assert.IsInstanceOfType(response, typeof(HttpResponseMessage));
            Assert.AreEqual(response.StatusCode, HttpStatusCode.InternalServerError);
        }
Beispiel #2
0
        public HttpResponseMessage PutPatient(int id, PatientDetailDto patientdto)
        {
            Patient patient = new Patient()
            {
                Id               = patientdto.Id,
                Name             = patientdto.Name,
                Age              = patientdto.Age,
                Gender           = patientdto.Gender,
                Weight           = patientdto.Weight,
                DOB              = patientdto.DOB,
                ConsultingDoctor = patientdto.ConsultingDoctor,
                Disease          = patientdto.Disease,
                Contact          = patientdto.Contact,
                RegistrationFee  = patientdto.RegistrationFee,
                LastVisit        = patientdto.LastVisit,
                StatusFlag       = 0
            };


            if (!PatientExists(id))
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
            db.Entry(patient).State = EntityState.Modified;
            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, patient));
        }
Beispiel #3
0
        public IActionResult UpdatePatientDetails(int id, [FromBody] PatientDetailDto pdDto)
        {
            if (pdDto == null || id != pdDto.UserId)
            {
                return(BadRequest(ModelState));
            }
            //used to update only logged in user patient details
            //int Userid = 0;
            //int.TryParse(User.Identity.Name, out Userid);

            //if (pdDto == null || Userid==0)
            //{
            //    return BadRequest(ModelState);
            //}

            var obj = _mapper.Map <PatientDetail>(pdDto);

            //  obj.UserId = Userid;
            if (!_pdRepo.UpdatePatientDetail(obj))
            {
                ModelState.AddModelError("", $"Something went wrong when updating the record {pdDto}");
                return(StatusCode(500, ModelState));
            }

            return(NoContent());
        }
Beispiel #4
0
        public HttpResponseMessage PostPatient(PatientDetailDto patientdto)
        {
            Patient patient = new Patient()
            {
                Id               = patientdto.Id,
                Name             = patientdto.Name,
                Age              = patientdto.Age,
                Gender           = patientdto.Gender,
                Weight           = patientdto.Weight,
                DOB              = patientdto.DOB,
                ConsultingDoctor = patientdto.ConsultingDoctor,
                Disease          = patientdto.Disease,
                Contact          = patientdto.Contact,
                RegistrationFee  = patientdto.RegistrationFee,
                LastVisit        = patientdto.LastVisit,
                StatusFlag       = 0
            };


            db.Patients.Add(patient);
            try
            {
                db.SaveChanges();
            }
            catch (Exception) //DbUpdateException
            {
                //    throw new DbUpdateException("The request couldn't be successfully Executed !!");
                //}
                //catch (DbEntityValidationException ex)
                //{
                //    var errorMessages = ex.EntityValidationErrors
                //            .SelectMany(x => x.ValidationErrors)
                //            .Select(x => x.ErrorMessage);
                //    var fullErrorMessage = string.Join( " ; ", errorMessages);
                //    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);
                //    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
            //Loads the newly updated data in the patient with reference of foriegn doctor table
            db.Entry(patient).Reference(x => x.Doctor).Load();
            //var dto = new PatientIdDto()
            //{
            //    Id = patient.Id
            //};
            //returns Response 201 and dto object with it.
            var response = Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new StringContent("" + patient.Id, Encoding.UTF8, "application/json");

            return(response);
        }