Beispiel #1
0
 public ActionResult PatientRegister(Patient patientr)
 {
     ViewBag.Message1 = "";
     ViewBag.Message2 = "";
     if (ModelState.IsValid)
     {
         using (PatientRegisterModel prm = new PatientRegisterModel())
         {
             var v1 = prm.Patients.Where(a => a.username.Equals(patientr.username)).FirstOrDefault();
             if (v1 != null)
             {
                 ViewBag.Message2 = "Username already exists";
                 return(View("PatientRegister", patientr));
             }
             var v2 = prm.Patients.Where(a => a.email.Equals(patientr.email)).FirstOrDefault();
             if (v2 != null)
             {
                 ViewBag.Message1 = "Email already exists";
                 return(View("PatientRegister", patientr));
             }
             else
             {
                 prm.Patients.Add(patientr);
                 prm.SaveChanges();
                 return(RedirectToAction("PatientPanel"));
             }
         }
     }
     return(RedirectToAction("PatientLogin"));
 }
        public async Task <ActionResult> RegisterPatient(PatientRegisterModel model)
        {
            IdentityResult result = null;

            if (ModelState.IsValid)
            {
                Address address = new Address
                {
                    Street  = model.Address.Street,
                    ZipCode = model.Address.ZipCode,
                    City    = model.Address.City,
                    Country = model.Address.Country,
                    Id      = model.Id
                };
                Patient patient = new Patient
                {
                    Name      = model.Name,
                    LastName  = model.LastName,
                    PatientId = model.Id,
                    PESEL     = model.PESEL
                };
                try
                {
                    var user = new ApplicationUser()
                    {
                        Id = model.Id, Email = model.Email, UserName = model.Email, PhoneNumber = model.ContactNumber
                    };

                    result = await userManager.CreateAsync(user, model.Password);
                }
                catch (Exception ex)
                {
                    throw;
                }
                if (result.Succeeded)
                {
                    userManager.AddToRole(patient.PatientId, model.Role);

                    db.Patients.Add(patient);
                    db.Addresses.Add(address);
                    db.SaveChanges();
                    RedirectToAction("GetPatients", "SuperAdmins");
                }
                else
                {
                    ViewBag.msg = "Problem was accured while addind new patient";
                    return(View());
                }
            }
            return(RedirectToAction("GetPatients", "SuperAdmins"));
        }
Beispiel #3
0
        public IActionResult Register(PatientRegisterModel input)
        {
            using var db = new DatabaseContext();
            // tutaj sprawdzanie czy login jest unikalny
            if (db.Patients.SingleOrDefault(x => x.PESEL == input.PESEL) != null)
            {
                return(BadRequest("Duplicate PESEL"));
            }

            if (input.PESEL.Length == 11 && input.PESEL.All(char.IsDigit))
            {
                db.Patients.Add(new Patient()
                {
                    PESEL    = input.PESEL,
                    Name     = input.Name,
                    Lastname = input.Lastname
                });
                db.SaveChanges();
                return(NoContent());
            }
            return(BadRequest());
        }