public async Task <ActionResult> DeleteConfirmed(int id)
        {
            PhysiciansGroup physiciansGroup = await _db.PhysiciansGroup.FindAsync(id);

            _db.PhysiciansGroup.Remove(physiciansGroup);
            await _db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit(PhysiciansGroup physiciansGroup)
        {
            if (ModelState.IsValid)
            {
                _db.Entry(physiciansGroup).State = EntityState.Modified;
                await _db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(physiciansGroup));
        }
        public async Task <ActionResult> Create(PhysiciansGroup physiciansGroup)
        {
            if (ModelState.IsValid)
            {
                var existingUser = await UserManager.FindByNameAsync(physiciansGroup.Email);

                if (existingUser == null)
                {
                    _db.PhysiciansGroup.Add(physiciansGroup);
                    await _db.SaveChangesAsync();


                    var user = new ApplicationUser
                    {
                        UserName = physiciansGroup.Email,
                        Email    = physiciansGroup.Email
                    };
                    var password = "******" + physiciansGroup.NPI + "#PG1013"; // + physiciansGroup.Id;
                    var result   = await UserManager.CreateAsync(user, password);

                    if (result.Succeeded)
                    {
                        user.Role        = "PhysiciansGroup";
                        user.CCMid       = physiciansGroup.Id;
                        user.FirstName   = physiciansGroup.GroupName;
                        user.LastName    = physiciansGroup.NPI.ToString();
                        user.PhoneNumber = physiciansGroup.MainPhoneNumber;

                        await UserManager.AddToRoleAsync(user.Id, "PhysiciansGroup");

                        await _db.SaveChangesAsync();

                        ViewBag.Message  = "Physician Group Portal Created.";
                        ViewBag.Username = user.Email;
                        ViewBag.Password = password;

                        return(View(physiciansGroup));
                    }

                    _db.PhysiciansGroup.Remove(physiciansGroup);
                    await _db.SaveChangesAsync();

                    ViewBag.Message = "Error: " + result.Errors.FirstOrDefault();
                    return(View(physiciansGroup));
                }

                ViewBag.Message = "Email Already Exists! Physician Group Portal Not Created!.";
            }

            return(View(physiciansGroup));
        }
        // GET: PhysiciansGroup/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PhysiciansGroup physiciansGroup = await _db.PhysiciansGroup.FindAsync(id);

            if (physiciansGroup == null)
            {
                return(HttpNotFound());
            }
            return(View(physiciansGroup));
        }