コード例 #1
0
        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")));
            }
        }
コード例 #2
0
        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());
            }
        }
コード例 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            AssistantModel assistantModel = db.AssistantModels.Find(id);

            db.AssistantModels.Remove(assistantModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #4
0
 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));
 }
コード例 #5
0
        public IActionResult DeleteAssistant(int AssistantID)
        {
            AssistantModel deletedAssistant = adminRepository.DeleteAssistant(AssistantID);

            if (deletedAssistant != null)
            {
                TempData["message"] = $"Deleted succesfully {deletedAssistant.LastName}.";
            }
            return(RedirectToAction(nameof(AssistantIndex)));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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)));
        }
コード例 #9
0
 public IActionResult EditAssistant(AssistantModel assistant)
 {
     if (ModelState.IsValid)
     {
         adminRepository.SaveAssistant(assistant);
         return(RedirectToAction(nameof(AssistantIndex)));
     }
     else
     {
         return(View(assistant));
     }
 }
コード例 #10
0
        // 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));
        }
コード例 #11
0
 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();
 }
コード例 #12
0
        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")));
        }
コード例 #13
0
        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)));
        }
コード例 #14
0
 public void EditAssistant(AssistantModel assistant)
 {
     adminContext.Assistants.Update(assistant);
     adminContext.SaveChanges();
 }