Пример #1
0
        public ActionResult Create(PatientFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Cities = _unitOfWork.Cities.GetCities();
                return(View("PatientForm", viewModel));
            }

            var patient = new Patient
            {
                Name      = viewModel.Name,
                Phone     = viewModel.Phone,
                Address   = viewModel.Address,
                DateTime  = DateTime.Now,
                BirthDate = viewModel.GetBirthDate(),
                Height    = viewModel.Height,
                Weight    = viewModel.Weight,
                CityId    = viewModel.City,
                Sex       = viewModel.Sex,
                Token     = (2018 + _unitOfWork.Patients.GetPatients().Count()).ToString().PadLeft(7, '0')
            };

            _unitOfWork.Patients.Add(patient);
            _unitOfWork.Complete();
            return(RedirectToAction("Index", "Patients"));

            // TODO: BUG redirect to detail
            //return RedirectToAction("Details", new { id = viewModel.Id });
        }
Пример #2
0
        public ActionResult Update(PatientFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Cities = _unitOfWork.Cities.GetCities();
                return(View("PatientForm", viewModel));
            }


            var patientInDb = _unitOfWork.Patients.GetPatient(viewModel.Id);

            patientInDb.Id        = viewModel.Id;
            patientInDb.Name      = viewModel.Name;
            patientInDb.Phone     = viewModel.Phone;
            patientInDb.BirthDate = viewModel.GetBirthDate();
            patientInDb.Address   = viewModel.Address;
            patientInDb.Height    = viewModel.Height;
            patientInDb.Weight    = viewModel.Weight;
            patientInDb.Sex       = viewModel.Sex;
            patientInDb.CityId    = viewModel.City;

            _unitOfWork.Complete();
            return(RedirectToAction("Index", "Patients")
                   );
        }
Пример #3
0
        public ActionResult AddPatient(PatientFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Cities  = _unitofWork.Cities.GetCities();
                viewModel.Heading = "New Patient";

                return(View(viewModel));
            }
            var patient = new Patient()
            {
                Name      = viewModel.Name,
                Address   = viewModel.Address,
                BirthDate = viewModel.GetBirthDate(),
                CityId    = viewModel.City,
                DateTime  = DateTime.Now,
                Sex       = viewModel.Sex,
                DStatus   = true,
                Phone     = viewModel.Phone,
                Height    = viewModel.Height,
                Weight    = viewModel.Weight,
                Token     = DateTime.Now.ToString("ddMMyyyy") + new Random(1000).Next(1000).ToString()
            };

            _unitofWork.Patients.Add(patient);
            _unitofWork.Complete();
            return(RedirectToAction("Index"));
        }
        public IActionResult Create(PatientFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Cities = _unitOfWork.Cities.GetCities();
                return(View("PatientForm", viewModel));
            }
            var user    = userManager.Users.FirstOrDefault(x => x.Email == User.Identity.Name);
            var patient = new Patient
            {
                Name      = User.Identity.Name,
                Phone     = viewModel.Phone,
                Address   = viewModel.Address,
                DateTime  = DateTime.Now,
                BirthDate = viewModel.GetBirthDate(),
                Height    = viewModel.Height,
                Weight    = viewModel.Weight,
                CityId    = viewModel.City,
                Sex       = viewModel.Sex,
                Token     = (2018 + _unitOfWork.Patients.GetPatients().Count()).ToString().PadLeft(7, '0'),
                UserId    = user.Id
            };

            //var userU = new ApplicationUser
            //{
            //    PhoneNumber = viewModel.Phone

            //};

            // var result = userManager.cre(userU);

            _unitOfWork.Patients.Add(patient);
            _unitOfWork.Complete();
            return(RedirectToAction("Index", "Account"));

            // TODO: BUG redirect to detail
            //return RedirectToAction("Details", new { id = viewModel.Id });
        }