public async Task <IActionResult> OnPostAsync() { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = registerModel.Email, Email = registerModel.Email, FirstName = registerModel.FirstName, LastName = registerModel.LastName, }; var result = await _userManager.CreateAsync(user, registerModel.Password); var medicalHistory = new MedicalHistory(); var path = Path.Combine(_hostingEnvironment.WebRootPath, "images", "Default-welcomer.png"); var imageFileStream = System.IO.File.OpenRead(path); byte[] imageByteArray; using (var memoryStream = new MemoryStream()) { imageFileStream.CopyTo(memoryStream); imageByteArray = memoryStream.ToArray(); } var patient = new Models.Patient { Id = user.Id, User = user, MedicalHistory = medicalHistory, Picture = new ProfilePicture() { Id = Guid.NewGuid().ToString(), ImageData = imageByteArray } }; var pat = await _userManager.FindByIdAsync(patient.Id); await _userManager.AddToRoleAsync(pat, "Patient"); context.Patient.Add(patient); await context.SaveChangesAsync(); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); return(RedirectToPage("/Patient/Edit")); } else { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } } return(Page()); }
public async Task <IActionResult> OnPost() { ApplicationUser user = new ApplicationUser { UserName = Doctor.Email, Email = Doctor.Email, FirstName = Doctor.FirstName, LastName = Doctor.LastName, PhoneNumber = Doctor.Phone }; await _userManager.CreateAsync(user, Doctor.Password); var path = Path.Combine(_hostingEnvironment.WebRootPath, "images", "Default-welcomer.png"); var imageFileStream = System.IO.File.OpenRead(path); byte[] imageByteArray; using (var memoryStream = new MemoryStream()) { imageFileStream.CopyTo(memoryStream); imageByteArray = memoryStream.ToArray(); } Models.Doctor dct = new Models.Doctor { Id = user.Id, Sex = Doctor.Sex, Specializaiton = Doctor.Specialization, User = user, Picture = new ProfilePicture() { Id = Guid.NewGuid().ToString(), ImageData = imageByteArray } }; var doc = await _userManager.FindByIdAsync(dct.Id); await _userManager.AddToRoleAsync(doc, "Doctor"); _context.Doctor.Add(dct); await _context.SaveChangesAsync(); return(RedirectToPage("/Doctor/Index")); }
public async Task <IActionResult> OnPost() { var tmp = _context.Announcement.ToList(); int max = 0; foreach (var item in tmp) { if (item.Number >= max) { max = item.Number; } } an.Number = max + 1; an.Hour = DateTime.Now.ToString("HH:mm"); an.Date = DateTime.Now.Date.ToString("dd/MM/yyy"); an.Id = Guid.NewGuid().ToString(); await _context.AddAsync(an); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }