public async Task <ActionResult> AddManager(ManagerVM model)
        {
            ApplicationDbContext context = new ApplicationDbContext();

            var            UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
            PasswordHasher hasher      = new PasswordHasher();

            ApplicationUser AppUser = new ApplicationUser()
            {
                Id                   = Guid.NewGuid().ToString(),
                Email                = model.Email,
                UserName             = model.Username,
                SecurityStamp        = Guid.NewGuid().ToString(),
                PhoneNumber          = model.Phone,
                LockoutEnabled       = false,
                AccessFailedCount    = 0,
                PhoneNumberConfirmed = false,
                TwoFactorEnabled     = false,
                EmailConfirmed       = false,
                PasswordHash         = hasher.HashPassword(model.Password)
            };

            string[] FullName = model.FullName.Split(new string[] { " " }, StringSplitOptions.None);
            Manager  mgr      = new Manager()
            {
                ID        = AppUser.Id,
                FirstName = FullName[0].ToString(),
                LastName  = FullName[1].ToString(),
                Phone     = model.Phone,
                ClientID  = model.clientID
            };

            db.Manager.Add(mgr);
            context.Users.Add(AppUser);

            await context.SaveChangesAsync();

            await db.SaveChangesAsync();

            RoleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            if (!RoleManager.RoleExists("Manager"))
            {
                var roleresult = RoleManager.Create(new IdentityRole("Manager"));
            }
            var Result = UserManager.AddToRole(AppUser.Id, "Manager");

            DisplayClientBuilding ObjDCB = new DisplayClientBuilding()
            {
                ManagerID = AppUser.Id, ClientID = model.clientID
            };

            return(RedirectToAction("SelectBuilding", ObjDCB));
        }
示例#2
0
        public async Task <ActionResult> Create([Bind(Include = "ID,FirstName,LastName,Phone,Username,Password,Created,isTemPWord,aptID,LogintableID")] Tenant tenant)
        {
            if (ModelState.IsValid)
            {
                db.Tenant.Add(tenant);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.aptID = new SelectList(db.Apartment, "ID", "ApartmentNumber", tenant.aptID);
            return(View(tenant));
        }
        public async Task <ActionResult> deleteClient(Clients model)
        {
            if (ModelState.IsValid)
            {
                var client = await db.Clients.FindAsync(model.ID);

                db.Clients.Remove(client);
                await db.SaveChangesAsync();
            }



            return(RedirectToAction("ClientIndex"));
        }
        public async Task <JsonResult> FromJson(List <JsonVM> name)
        {
            foreach (var item in name)
            {
                switch (item.Controller)
                {
                case "1":


                    var mppt1 = new MasterProfileFields {
                        Controller = item.Controller,
                        Label      = item.TextboxLabel
                    };

                    db.MasterProfileFields.Add(mppt1);
                    await db.SaveChangesAsync();

                    break;

                case "2":
                    var mppt2 = new MasterProfileFields {
                        Controller = item.Controller,
                        Label      = item.TextboxLabel
                    };

                    db.MasterProfileFields.Add(mppt2);
                    await db.SaveChangesAsync();

                    break;

                case "3":
                    var mppt3 = new MasterProfileFields {
                        Controller = item.Controller,
                        Label      = item.TextboxLabel
                    };

                    db.MasterProfileFields.Add(mppt3);
                    await db.SaveChangesAsync();

                    break;

                case "4":
                    var mppt4 = new MasterProfileFields {
                        Controller = item.Controller,
                        Label      = item.TextboxLabel
                    };

                    db.MasterProfileFields.Add(mppt4);
                    await db.SaveChangesAsync();

                    break;

                case "5":
                    var mppt5 = new MasterProfileFields {
                        Controller = item.Controller,
                        Label      = item.TextboxLabel
                    };

                    db.MasterProfileFields.Add(mppt5);
                    await db.SaveChangesAsync();

                    break;
                }
            }



            // Can process the data any way we want here,
            // e.g., further server-side validation, save to database, etc
            return(Json(name));
        }