public async Task <IActionResult> NewDoctor(DoctorDto model, List <IFormFile> files) { var ee = ""; if (ModelState.IsValid) { try { string succed; succed = await _doctor.Create(model); if (succed == "true") { var user = await userManager.FindByNameAsync(model.EmailAddress); var user1 = await _context.Doctor.FirstOrDefaultAsync(x => x.UserId == user.Id); //try to update the Doctor Reg //Doctor Reg string numberid = user1.Id.ToString("D3"); user1.DoctorReg = "DOC/" + numberid; //try to update the user profile pict //profile pic upload var fileName = await _upload.UploadFile(files, _env); user1.ProfilePicture = "/Uploads/" + fileName; _context.Entry(user1).State = EntityState.Modified; await _context.SaveChangesAsync(); TempData["success"] = "Doctor with Username " + model.Fullname + "Added Successfully"; return(RedirectToAction("NewDoctor")); } else { TempData["error1"] = succed; } } catch (Exception e) { ee = e.ToString(); } } var allErrors = ModelState.Values.SelectMany(v => v.Errors); TempData["error"] = "Creation of new Doctor not successful" + ee; ViewData["DepartmentId"] = new SelectList(_context.Departments, "Id", "DeptName", model.DepartmentId); ViewData["BloodGroupId"] = new SelectList(_context.BloodGroup, "Id", "Name", model.BloodGroupId); return(View(model)); }
public string Add([FromBody] Doctor AddDoctor) { try { context.Doctors.Single(s => s.DoctorName == AddDoctor.DoctorName && s.Contact == AddDoctor.Contact); return($"Doctor is already exists..."); } catch (Exception) { doctor.Create(AddDoctor); Doctor AddedDoctor = context.Doctors.ToList().Last(); return($"Welcome to the hospital {AddedDoctor.DisplayName}, Your id is {AddedDoctor.DoctorId}\nPlease remember it for infuture operations..."); } }