public async Task <ActionResult> Action(string id)
        {
            var roles = RoleManager.Roles.ToList();

            if (string.IsNullOrEmpty(id))                                        //create form
            {
                var model = new UsersActionViewModel()
                {
                    Roles = roles
                };
                return(PartialView("_Action", model));
            }
            else                                                   // edit form
            {
                var user = await UserManager.FindByIdAsync(id);

                var model = new UsersActionViewModel()
                {
                    Id       = user.Id,
                    FullName = user.FullName,
                    Email    = user.Email,
                    UserName = user.UserName,
                    Address  = user.Address,
                    Country  = user.Country,
                    City     = user.City,

                    Roles = roles
                };
                return(PartialView("_Action", model));
            }
        }
        public async Task <ActionResult> Action(UsersActionViewModel model)
        {
            IdentityResult result = null;

            if (!string.IsNullOrEmpty(model.Id))                           // edit a accommodation type
            {
                var user = await UserManager.FindByIdAsync(model.Id);

                user.FullName = model.FullName;
                user.UserName = model.UserName;
                user.Email    = model.Email;
                user.City     = model.City;
                user.Address  = model.Address;
                user.Country  = model.Country;

                result = await UserManager.UpdateAsync(user);
            }
            else                                          // create a new accommodation type
            {
                var user = new ApplicationUser();

                user.FullName = model.FullName;
                user.UserName = model.UserName;
                user.Email    = model.Email;
                user.City     = model.City;
                user.Address  = model.Address;
                user.Country  = model.Country;

                result = await UserManager.CreateAsync(user);
            }


            return(Json(new { success = result.Succeeded, message = string.Join("</br>", result.Errors) }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        public ActionResult Delete(string ID)
        {
            UsersActionViewModel model = new UsersActionViewModel();

            model.ID = ID;

            return(PartialView("_Delete", model));
        }
Esempio n. 4
0
        public async Task <ActionResult> Delete(string id)
        {
            UsersActionViewModel model = new UsersActionViewModel();

            var user = await UserManager.FindByIdAsync(id);

            model.Id = user.Id;

            return(PartialView("_Delete", model));
        }
Esempio n. 5
0
        public async Task <JsonResult> Action(UsersActionViewModel model, bool isDeleted = false)
        {
            JsonResult     json   = new JsonResult();
            IdentityResult result = null;

            if (model.Id != null && isDeleted == false)
            {
                //edit here
                var user = await UserManager.FindByIdAsync(model.Id);

                //dont allow to edit email and username
                user.UserName = model.Name;
                user.Email    = model.Email;
                user.FullName = model.FullName;
                user.Country  = model.Country;
                user.City     = model.City;
                user.Address  = model.Address;
                result        = await UserManager.UpdateAsync(user);
            }
            else if (model.Id != null && isDeleted == true)
            {
                //delete here
                var user = await UserManager.FindByIdAsync(model.Id);

                result = await UserManager.DeleteAsync(user);
            }

            else
            {
                //Create new User here with Role
                var user = new ApplicationUser();

                user.Email    = model.Email;
                user.UserName = model.Name;
                user.FullName = model.FullName;
                user.Country  = model.Country;
                user.City     = model.City;
                user.Address  = model.Address;

                result = await UserManager.CreateAsync(user, "123456");

                if (result.Succeeded)
                {
                    var role = await RoleManager.FindByIdAsync(model.RoleId);

                    result = await UserManager.AddToRoleAsync(user.Id, role.Name);
                }
            }

            json.Data = new { Success = result.Succeeded, Message = string.Join(",", result.Errors) };

            return(json);
        }
Esempio n. 6
0
        //user roles add and remove actions
        public async Task <ActionResult> GetUserRoles(string id)
        {
            UsersActionViewModel model = new UsersActionViewModel();

            var user = await UserManager.FindByIdAsync(id);

            var userRoleIDs = user.Roles.Select(x => x.RoleId).ToList();

            model.UserRole = RoleManager.Roles.Where(a => userRoleIDs.Contains(a.Id)).ToList();
            //model.UserRole = RoleManager.Roles.Where(a => a.Id.Contains(userRoleIDs)).ToList();
            model.Name  = user.UserName;
            model.Id    = id;
            model.Roles = RoleManager.Roles.Where(a => !userRoleIDs.Contains(a.Id)).ToList();

            return(PartialView("_GetUserRoles", model));
        }
Esempio n. 7
0
        public async Task <ActionResult> Action(string ID, bool isDelete = false)
        {
            UsersActionViewModel model = new UsersActionViewModel();

            ViewBag.isDelete = isDelete;

            model.Roles = RoleManager.Roles;

            if (!string.IsNullOrEmpty(ID) && isDelete)
            {
                //delete here
                ApplicationUser user = UserManager.FindById(ID);

                model.Id             = user.Id;
                model.Name           = user.UserName;
                model.Email          = user.Email;
                model.FullName       = user.FullName;
                model.Country        = user.Country;
                model.City           = user.City;
                model.Address        = user.Address;
                model.UserRolesNames = UserManager.GetRoles(user.Id).ToList();
            }

            else if (!string.IsNullOrEmpty(ID) && isDelete == false)
            {
                //edit here
                ApplicationUser user = await UserManager.FindByIdAsync(ID);

                //model.Id = int.Parse(user.Id);
                model.Id             = user.Id;
                model.Name           = user.UserName;
                model.Email          = user.Email;
                model.FullName       = user.FullName;
                model.Country        = user.Country;
                model.City           = user.City;
                model.Address        = user.Address;
                model.UserRolesNames = UserManager.GetRoles(user.Id).ToList();
            }
            else
            {
                //new entry
            }
            //model.AccomodationTypes = accomodationTypesService.GetAllAccomodationTypes();
            return(PartialView("_Action", model));
        }
        public async Task <ActionResult> Delete(UsersActionViewModel model)
        {
            IdentityResult result = null;

            if (!string.IsNullOrEmpty(model.Id))
            {
                var user = await UserManager.FindByIdAsync(model.Id);

                result = await UserManager.DeleteAsync(user);

                return(Json(new { success = result.Succeeded, message = string.Join("</br>", result.Errors) },
                            JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { success = false, message = "invalid user" }, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 9
0
        public async Task <JsonResult> Delete(UsersActionViewModel model)
        {
            JsonResult     json   = new JsonResult();
            IdentityResult result = null;

            if (!string.IsNullOrEmpty(model.ID))
            {
                var user = await UserManager.FindByIdAsync(model.ID);

                result = await UserManager.DeleteAsync(user);

                json.Data = new { Success = result.Succeeded, Message = string.Join(",", result.Errors) };
            }
            else
            {
                json.Data = new { Success = false, Message = "Invalid user" };
            }
            return(json);
        }
Esempio n. 10
0
        public async Task <JsonResult> Action(UsersActionViewModel model)
        {
            JsonResult json = new JsonResult();

            IdentityResult result = null;

            if (!string.IsNullOrEmpty(model.ID))
            {
                var user = await UserManager.FindByIdAsync(model.ID);

                //model.ID = user.Id;
                user.FullName = model.FullName;
                user.Email    = model.Email;
                user.UserName = model.UserName;
                user.Country  = model.Country;
                user.City     = model.City;
                user.Address  = model.Address;
                //Accomodation accomodation = _repoWrapper.Accomodations.Get(model.ID);
                //accomodation.Name = model.Name;
                //accomodation.RoleID = model.RoleID;
                //accomodation.Description = model.Description;

                //result = _repoWrapper.Accomodations.Update(accomodation);
                result = await UserManager.UpdateAsync(user);
            }
            else
            {
                var user = new HMSUser();

                //model.ID = user.Id;
                user.FullName = model.FullName;
                user.Email    = model.Email;
                user.UserName = model.UserName;
                user.Country  = model.Country;
                user.City     = model.City;
                user.Address  = model.Address;
                result        = await UserManager.CreateAsync(user);
            }


            json.Data = new { Success = result.Succeeded, Message = string.Join(",", result.Errors) };
            return(json);
        }
Esempio n. 11
0
        public async Task <ActionResult> Action(string id)
        {
            UsersActionViewModel model = new UsersActionViewModel();

            if (!string.IsNullOrEmpty(id))
            {
                // edit
                var user = await UserManager.FindByIdAsync(id);

                model.Id       = user.Id;
                model.FullName = user.FullName;
                model.Email    = user.Email;
                model.UserName = user.UserName;
                model.Country  = user.Country;
                model.City     = user.City;
                model.Address  = user.Address;
            }
            //model.AccomodationPackages = accomodationPackageService.GetAllAccomodationPackages();
            return(PartialView("_Action", model));
        }
Esempio n. 12
0
        public async Task <ActionResult> Action(string ID)
        {
            UsersActionViewModel model = new UsersActionViewModel();

            if (!string.IsNullOrEmpty(ID))
            {
                var user = await UserManager.FindByIdAsync(ID);

                model.ID       = user.Id;
                model.FullName = user.FullName;
                model.Email    = user.Email;
                model.UserName = user.UserName;
                model.Country  = user.Country;
                model.City     = user.City;
                model.Address  = user.Address;

                //model.Name = accomodation.Name;
                //model.Description = accomodation.Description;
            }
            //model.Roles = _repoWrapper.AccomodationPackages.GetAll().ToList();
            return(PartialView("_action", model));
        }
Esempio n. 13
0
        public async Task <ActionResult> Action(UsersActionViewModel model)
        {
            JsonResult     json   = new JsonResult();
            IdentityResult result = null;

            if (!string.IsNullOrEmpty(model.Id))
            {
                // edit
                var user = await UserManager.FindByIdAsync(model.Id);

                user.FullName = model.FullName;
                user.Email    = model.Email;
                user.UserName = model.UserName;
                user.Country  = model.Country;
                user.City     = model.City;
                user.Address  = model.Address;

                result = await UserManager.UpdateAsync(user);
            }
            else
            {
                // create
                var user = new HMSUser();

                user.FullName = model.FullName;
                user.Email    = model.Email;
                user.UserName = model.UserName;
                user.Country  = model.Country;
                user.City     = model.City;
                user.Address  = model.Address;

                result = await UserManager.CreateAsync(user);
            }

            json.Data = new { Success = result.Succeeded, Message = string.Join(" ", result.Errors) };

            return(json);
        }