public ActionResult Create(string ThanaID, string ClinicName)
 {
     CommunityClinic aCommunityClinic = new CommunityClinic();
     aCommunityClinic.ClinicName = ClinicName;
     aCommunityClinic.ThanaID = Convert.ToInt32(ThanaID);
     db.CommunityClinics.Add(aCommunityClinic);
     db.SaveChanges();
     int ClinicId = aCommunityClinic.CommunityClinicID;
     string user;
     string pass;
     //return RedirectToAction("SaveClinicResult");
     RandomNumberGenerator.Create("string");
        // pass = ClinicName + "_" + ThanaID;
     pass = GenerateRandomPassword();
     user = ClinicName.Replace(" ", string.Empty).ToLower() + "_" +
            (db.CommunityClinics.OrderByDescending(x => x.CommunityClinicID).First().CommunityClinicID+1);
     int Thana = Convert.ToInt32(ThanaID);
     string user1 = db.Thanas.Where(x => x.ThanaID == Thana).First().ThanaName.ToLower() +
                    "_"+(db.CommunityClinics.OrderByDescending(x => x.CommunityClinicID).First().CommunityClinicID) +
                    1;
     TempData["user"] = user;
     TempData["pass"] = pass;
     Account account = new Account() { UserName = user, Password = pass, UserRole = "Clinic", CommunityClinicID = ClinicId };
     db.Accounts.Add(account);
     db.SaveChanges();
     return Redirect("SaveClinicResult");
 }
        public ActionResult Login(Account anAccount)
        {
            //ViewBag.Message = "Login Page";

            int count =
                db.Accounts.Where(x => x.UserName == anAccount.UserName && x.Password == anAccount.Password).Count();
            if (count == 0)
            {
                ViewBag.Msg = "Invalid User";
                return View();
            }
            else if (count==1)
            {
               Account userAccount=new Account();
                var account =
                    db.Accounts.Where(x => x.UserName == anAccount.UserName && x.Password == anAccount.Password).ToList()
                        ;
                foreach (Account acc in account)
                {
                    userAccount.UserName = acc.UserName;
                    userAccount.UserRole = acc.UserRole;
                    userAccount.CommunityClinicID = acc.CommunityClinicID;

                }

                FormsAuthentication.SetAuthCookie(userAccount.UserName + "|" + userAccount.UserRole + "|" + userAccount.CommunityClinicID, false);
                if (userAccount.UserRole=="Clinic") { return RedirectToAction("HomePageClinic", "Home"); }
                else if (userAccount.UserRole == "Head") { return RedirectToAction("HomePageHeadOffice", "Home"); }
                return RedirectToAction("Index", "Home");
            }
            //string name = "";

            //if (HttpContext.Current.Request.IsAuthenticated)
            //{
            //    name = Convert.ToInt32(HttpContext.Current.User.Identity.Name.Split('|')[0]);
            //}

            return View();
        }