public async Task <IActionResult> GetAssistantsAsync() { if (_db.Assistants.Count() != 0) { List <AssistantModel> result = new List <AssistantModel>(); var findAssistants = _db.Assistants.ToList(); foreach (Assistant assistant in findAssistants) { var findUser = await _userManager.FindByIdAsync(assistant.as_user_id); AssistantModel assistantModel = new AssistantModel(); assistantModel.as_mname = assistant.as_mname; assistantModel.as_fname = assistant.as_fname; assistantModel.as_lname = assistant.as_lname; assistantModel.as_dr_id = assistant.as_dr_id; assistantModel.as_email = findUser.Email; assistantModel.as_phone = findUser.PhoneNumber; assistantModel.as_username = findUser.UserName; result.Add(assistantModel); } return(Ok(new JsonResult(result))); } else { return(BadRequest(new JsonResult("No Assistants to show"))); } }
public async Task <IActionResult> GetAssistantById([FromRoute] string id) { var findUser = await _userManager.FindByIdAsync(id); var findAssistant = _db.Assistants.FirstOrDefault(d => d.as_user_id == id); if (findAssistant != null && findUser != null) { AssistantModel assistant = new AssistantModel(); assistant.as_fname = findAssistant.as_fname; assistant.as_mname = findAssistant.as_mname; assistant.as_lname = findAssistant.as_lname; assistant.as_dr_id = findAssistant.as_dr_id; assistant.as_email = findUser.Email; assistant.as_phone = findUser.PhoneNumber; assistant.as_username = findUser.UserName; assistant.as_password = findUser.PasswordHash; assistant.ConfirmPassword = findUser.PasswordHash; return(Ok(new JsonResult(assistant))); } else { return(NotFound()); } }
public ActionResult DeleteConfirmed(int id) { AssistantModel assistantModel = db.AssistantModels.Find(id); db.AssistantModels.Remove(assistantModel); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Confrimed,StageDetails,OtherUserConfirmed")] AssistantModel assistantModel) { if (ModelState.IsValid) { db.Entry(assistantModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(assistantModel)); }
public IActionResult DeleteAssistant(int AssistantID) { AssistantModel deletedAssistant = adminRepository.DeleteAssistant(AssistantID); if (deletedAssistant != null) { TempData["message"] = $"Deleted succesfully {deletedAssistant.LastName}."; } return(RedirectToAction(nameof(AssistantIndex))); }
public ActionResult Create([Bind(Include = "Id,Confrimed,StageDetails,OtherUserConfirmed")] AssistantModel assistantModel) { if (ModelState.IsValid) { db.AssistantModels.Add(assistantModel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(assistantModel)); }
public AssistantModel DeleteAssistant(int AssistantID) { AssistantModel dbEntry = adminContext.Assistants.FirstOrDefault(p => p.Id == AssistantID); if (dbEntry != null) { adminContext.Assistants.Remove(dbEntry); adminContext.SaveChanges(); } return(dbEntry); }
public async Task <IActionResult> UpdateAssistant([FromRoute] string id, [FromBody] AssistantModel assistant) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //here we will hold all the errors of registration List <string> errorList = new List <string>(); var findAssistant = _db.Assistants.FirstOrDefault(d => d.as_user_id == id); var findUser = await _userManager.FindByIdAsync(id); if (findAssistant == null && findUser == null) { return(NotFound()); } // If the assistant was found findAssistant.as_fname = assistant.as_fname; findAssistant.as_mname = assistant.as_mname; findAssistant.as_lname = assistant.as_lname; findAssistant.as_dr_id = assistant.as_dr_id; _db.Entry(findAssistant).State = EntityState.Modified; var username = await _userManager.SetUserNameAsync(findUser, assistant.as_username); var email = await _userManager.SetEmailAsync(findUser, assistant.as_email); var phone = await _userManager.SetPhoneNumberAsync(findUser, assistant.as_phone); var updateUser = await _userManager.UpdateAsync(findUser); if (updateUser.Succeeded) { await _db.SaveChangesAsync(); return(Ok(new JsonResult("The Assistant with id " + id + " and name " + findAssistant.as_fname + " " + findAssistant.as_mname + " " + findAssistant.as_lname + " is updated"))); } else { foreach (var error in updateUser.Errors) { ModelState.AddModelError("", error.Description); errorList.Add(error.Description); } } return(BadRequest(new JsonResult(errorList))); }
public IActionResult EditAssistant(AssistantModel assistant) { if (ModelState.IsValid) { adminRepository.SaveAssistant(assistant); return(RedirectToAction(nameof(AssistantIndex))); } else { return(View(assistant)); } }
// GET: Assistant/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AssistantModel assistantModel = db.AssistantModels.Find(id); if (assistantModel == null) { return(HttpNotFound()); } return(View(assistantModel)); }
public void SaveAssistant(AssistantModel assistant) { if (assistant.Id == 0) { adminContext.Assistants.Add(assistant); } else { AssistantModel dbEntry = adminContext.Assistants.FirstOrDefault(p => p.Id == assistant.Id); if (dbEntry != null) { dbEntry.FirstName = assistant.FirstName; dbEntry.LastName = assistant.LastName; } } adminContext.SaveChanges(); }
public async Task <IActionResult> UpdateAssistant([FromRoute] string id, [FromBody] AssistantModel assistant) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var findAssistant = _db.Assistants.FirstOrDefault(d => d.as_user_id == id); var findUser = await _userManager.FindByIdAsync(id); if (findAssistant == null && findUser == null) { return(NotFound()); } // If the assistant was found findAssistant.as_fname = assistant.as_fname; findAssistant.as_mname = assistant.as_mname; findAssistant.as_lname = assistant.as_lname; findAssistant.as_dr_id = assistant.as_dr_id; _db.Entry(findAssistant).State = EntityState.Modified; var username = await _userManager.SetUserNameAsync(findUser, assistant.as_username); var email = await _userManager.SetEmailAsync(findUser, assistant.as_email); var phone = await _userManager.SetPhoneNumberAsync(findUser, assistant.as_phone); var updateUser = await _userManager.UpdateAsync(findUser); await _db.SaveChangesAsync(); return(Ok(new JsonResult("The Assistant with id " + id + " and name " + findAssistant.as_fname + " " + findAssistant.as_mname + " " + findAssistant.as_lname + " is updated"))); }
public async Task <IActionResult> AddAssistant([FromBody] AssistantModel assistant) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //here we will hold all the errors of registration List <string> errorList = new List <string>(); var user = new IdentityUser { Email = assistant.as_email, UserName = assistant.as_username, PhoneNumber = assistant.as_phone, SecurityStamp = Guid.NewGuid().ToString() }; var result = await _userManager.CreateAsync(user, assistant.as_password); if (result.Succeeded) { var role = await _userManager.AddToRoleAsync(user, "Assistant"); if (role.Succeeded) { //Sending Comfirmation Email var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { UserId = user.Id, Code = code }, protocol: HttpContext.Request.Scheme); await _emailsender.SendEmailAsync(user.Email, "MyClinic.com - Confirm Your Email", "Please confirm your e-mail by clicking this link: <a href=\"" + callbackUrl + "\">click here</a>"); var newAssistant = new Assistant { as_user_id = user.Id, as_fname = assistant.as_fname, as_mname = assistant.as_mname, as_lname = assistant.as_lname, as_dr_id = assistant.as_dr_id }; var addAssistant = await _db.Assistants.AddAsync(newAssistant); if (addAssistant != null) { await _db.SaveChangesAsync(); return(Ok(new { AssistantId = user.Id, AssistantUsername = user.UserName, AssistantEmail = user.Email, status = 1, message = "Registration of assistant " + assistant.as_fname + " Succeded" })); } } } else { foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); errorList.Add(error.Description); } } return(BadRequest(new JsonResult(errorList))); }
public void EditAssistant(AssistantModel assistant) { adminContext.Assistants.Update(assistant); adminContext.SaveChanges(); }