Exemple #1
0
        public IHttpActionResult CreatePatient(PatientBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var patient = new Patient()
            {
                FirstName    = model.FirstName,
                LastName     = model.LastName,
                HasInsurance = true,
                DateOfBirth  = model.DateOfBirth,
                Email        = model.Email,
            };

            DbContext.Patients.Add(patient);
            DbContext.SaveChanges();

            var url = Url.Link("PatientById", new { Id = patient.Id });

            var viewModel = new PatientViewModel(patient);

            return(Created(url, viewModel));
        }
        public PatientViewModel CreatePatient(PatientBindingModel patientBindingModel)
        {
            var model = new Patient
            {
                FirstName     = patientBindingModel.FirstName,
                LastName      = patientBindingModel.LastName,
                Login         = patientBindingModel.Login,
                Bonus         = 0,
                Password      = patientBindingModel.Password, // TODO шифровать!!!!!!!!!!!!!!!!
                PatientStatus = PatientStatus.Active,
                Phone         = patientBindingModel.Phone
            };

            _patientRepository.CreatePatient(model);

            return(new PatientViewModel
            {
                Id = model.Id,
                Login = model.Login,
                FirstName = model.FirstName,
                LastName = model.LastName,
                Bonus = model.Bonus,
                PatientStatus = model.PatientStatus.ToString(),
                Phone = model.Phone
            });
        }
        public HttpResponseMessage Post([FromBody] PatientBindingModel value)
        {
            try
            {
                Patient patient = m_repository.GetById(value.Id);
                patient.IsMen                 = value.IsMen;
                patient.MedicalCardNumber     = value.MedicalCardNumber;
                patient.PersonInfo.Name       = value.Name;
                patient.PersonInfo.Surname    = value.Surname;
                patient.PersonInfo.Middlename = value.Middlename;

                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (EntityAlreadyExistsException exp)
            {
                return(ResponseCreator.GenerateResponse(HttpStatusCode.BadRequest, exp)); //new HttpResponseMessage(HttpStatusCode.BadRequest);
            }
            catch (EntityNotFoundException exp)
            {
                return(ResponseCreator.GenerateResponse(HttpStatusCode.NotFound, exp)); //new HttpResponseMessage(HttpStatusCode.BadRequest);
            }
            catch (Exception exp)
            {
                return(ResponseCreator.GenerateResponse(HttpStatusCode.InternalServerError, exp));//new HttpResponseMessage(HttpStatusCode.InternalServerError);
            }
        }
        public IHttpActionResult Create(PatientBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var patient = Mapper.Map <Patient>(model);

            DbContext.Patients.Add(patient);
            DbContext.SaveChanges();

            var patientModel = Mapper.Map <PatientViewModel>(patient);

            return(Ok(patientModel));
        }
Exemple #5
0
        public IHttpActionResult EditPatient(int id, PatientBindingModel model)
        {
            var patientToEdit = DbContext.Patients.FirstOrDefault(p => p.Id == id);

            if (patientToEdit == null)
            {
                return(NotFound());
            }

            patientToEdit.FirstName    = model.FirstName;
            patientToEdit.LastName     = model.LastName;
            patientToEdit.DateOfBirth  = model.DateOfBirth;
            patientToEdit.Email        = model.Email;
            patientToEdit.HasInsurance = model.HasInsurance;

            DbContext.SaveChanges();

            var viewModel = new PatientViewModel(patientToEdit);

            return(Ok(viewModel));
        }
        public IHttpActionResult Edit(int id, PatientBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var patient = DbContext.Patients.Where(p => p.Id == id).FirstOrDefault();

            if (patient == null)
            {
                return(NotFound());
            }

            Mapper.Map(model, patient);

            DbContext.SaveChanges();

            var patientModel = Mapper.Map <PatientViewModel>(patient);

            return(Ok(patientModel));
        }
Exemple #7
0
        public IHttpActionResult Put(int id, PatientBindingModel formData)
        {
            var patient = DbContext.Patients.FirstOrDefault(p => p.Id == id);

            if (patient == null)
            {
                return(NotFound());
            }

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

            Mapper.Map(formData, patient);

            DbContext.SaveChanges();

            var model = Mapper.Map <PatientViewModel>(patient);

            return(Ok(model));
        }
        public HttpResponseMessage Put([FromBody] PatientBindingModel value)
        {
            try
            {
                Patient patient = new Patient()
                {
                    MedicalCardNumber = value.MedicalCardNumber, IsMen = value.IsMen, DateOfBirth = value.DateOfBirth
                };
                PersonInfo pi = new PersonInfo(value.Surname, value.Name, value.Middlename);
                patient.PersonInfo = pi;
                m_repository.Create(patient);

                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (EntityAlreadyExistsException exp)
            {
                return(ResponseCreator.GenerateResponse(HttpStatusCode.BadRequest, exp)); //new HttpResponseMessage(HttpStatusCode.BadRequest);
            }
            catch (Exception exp)
            {
                return(ResponseCreator.GenerateResponse(HttpStatusCode.InternalServerError, exp)); //new HttpResponseMessage(HttpStatusCode.InternalServerError);
            }
        }
        public IHttpActionResult CreatePatient(PatientBindingModel patientBindingModel)
        {
            var patientViewModel = _patientService.CreatePatient(patientBindingModel);

            return(Ok(new ResponseModel(patientViewModel, "Аккаунт успешно создан! :)")));
        }