public async Task<ActionResult> AddingTenant(TenantVM newTenant)
        {
            try { 
            
           
            if (ModelState.IsValid)
            {
                var newtenant = new Tenant
                {
                    FirstName = newTenant.FirstName,
                    LastName = newTenant.LastName,
                    Phone = newTenant.Phone,
                    Created = DateTime.Now,
                    aptID = newTenant.aptID,
                    Username = newTenant.Username
                };
                db.Tenant.Add(newtenant);
                await db.SaveChangesAsync();
                return RedirectToAction("ApartmentProfile", new { ApartmentID = newTenant.aptID, BuildingID= newTenant.BuildingID });

            }
            }
                catch(Exception e){

                    ViewBag.Message = e.Message;
                
            }
            return View();
        }
 public ActionResult AddingTenant(int apartmentID, int BuildingID)
 {
         var newtenant = new TenantVM();
         newtenant.aptID = (int)apartmentID;
         newtenant.BuildingID = BuildingID;
         return View(newtenant);
 }
 public ActionResult AddingTenant(int? apartmentID, int BuildingID)
 {
     if (apartmentID != null)
     {
         var newtenant = new TenantVM();
         newtenant.aptID = (int)apartmentID;
         newtenant.BuildingID = BuildingID;
         return View(newtenant);
     }
     return View("page doesn't meet the required elements");
 }
        public async Task<JsonResult> AddingTenant(TenantVM newTenant)
        {
            try { 
            
           
            if (ModelState.IsValid)
            {

                string password ="";
                if (newTenant.GenerateAutomaticPassword == false){ password = newTenant.Password;}
                else{ password = PasswordGenerator.GeneratePassword("8").ToString();}

              
                var UserID = RegisterUsers.InsertUser(newTenant.Username, newTenant.Phone, password);
                var result = RegisterUsers.InserToRole("Tenant", UserID);
                
                var tenantdb = new Tenant
                {
                    ID = UserID,
                    FirstName = newTenant.FirstName,
                    LastName = newTenant.LastName,
                    Phone = newTenant.Phone,
                    Created = DateTime.Now,
                    aptID = newTenant.aptID,
                    Username = newTenant.Username
                };
                db.Tenant.Add(tenantdb);
                
                await db.SaveChangesAsync();         
                
                if(newTenant.EmailNotification==true)
                {
                    var aptNumber = db.Apartment.Find(newTenant.aptID).ApartmentNumber;

                    
                    string string1 = "Hi " + newTenant.FirstName +" "+ newTenant.LastName + ", An Account has been created for you by PointerWebApp.com ";
                    string string2 = "The login information for apartment: "+ aptNumber+" is below";
                    string string3 = "Username: "******"Temporary password: "******"Click the on this http://localhost:64083/Account/Manage link and follow the instructions to initiate your account ";
                    string string6 = "Company Description";
                    string string7 = "Find more information...";

                    string x = string.Format("{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n{6}\n", string1, string2, string3, string4, string5, string6, string7);

                    Gmail gmail = new Gmail("pointerwebapp", "Dmc10040!");
                    MailMessage msg = new MailMessage("*****@*****.**", tenantdb.Username);
                    msg.Subject = "Pointer Security New Account Notification";
                    msg.Body = x;
                    gmail.Send(msg);
                }

                var mydata = Json("");

                return new JsonResult { Data = mydata, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
             
                //return RedirectToAction("ApartmentProfile", new { ApartmentID = newTenant.aptID, BuildingID= newTenant.BuildingID });

            }
            }
                catch(Exception e){

                    ViewBag.Message = e.Message;
                
            }
            var mydata1 = Json("");

            return new JsonResult { Data = mydata1, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; ;
        }