Esempio n. 1
0
        public async Task <IActionResult> CreateGroup([FromBody] GroupViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Group group = new Group()
                    {
                        Name      = model.Name,
                        CaptainId = model.CaptainId,
                        GroupType = model.GroupType,
                        CreatedAt = DateTime.Now,
                        CreatedBy = model.CreatedBy,
                        UpdatedAt = model.UpdateddAt,
                        UpdatedBy = model.UpdatedBy
                    };

                    await _groupManager.CreateGroup(group);

                    return(Ok(ApiResponse(ApiResponseStatus.Success, group, $@"Group successfully added.")));
                }

                return(BadRequest(ApiResponse(ApiResponseStatus.Fail, GetModelStateErrors(ModelState), "Model validation failure.")));
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return(HandleException("1", e, "An error occurred while adding record. Please try again later."));
            }
        }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "Id,Name")] OperationGroup operationGroup)
        {
            if (ModelState.IsValid)
            {
                gm.CreateGroup(operationGroup);
                return(RedirectToAction("Index"));
            }

            return(View(operationGroup));
        }
        // GET: Setup
        public ActionResult DefaultUsers()
        {
            var user = UserManager.FindByName(AppConstants.DefaultUserName);

            if (user == null)
            {
                user = new ApplicationUser
                {
                    UserName             = AppConstants.DefaultUserName,
                    Email                = AppConstants.DefaultUserEmail,
                    EmailConfirmed       = true,
                    PhoneNumber          = AppConstants.MobilePhone,
                    PhoneNumberConfirmed = true
                };
                var result = UserManager.Create(user, AppConstants.DefaultPass);
                result = UserManager.SetLockoutEnabled(user.Id, false);
            }

            var adminRole = RoleManager.FindByName(AppConstants.AdminRoleName);

            if (adminRole == null)
            {
                adminRole = new ApplicationRole(AppConstants.AdminRoleName);
                var roleresult = RoleManager.Create(adminRole);
            }

            var group = GroupManager.FindByName(AppConstants.SuperAdminsGroup);

            if (group == null)
            {
                group = new ApplicationGroup(AppConstants.SuperAdminsGroup, "Full Access to All");
                GroupManager.CreateGroup(group);
            }

            var userBlongToGroup = GroupManager.IsUserBlongToGroup(user.Id, group.Id);

            if (userBlongToGroup == false)
            {
                GroupManager.SetUserGroups(user.Id, new string[] { group.Id });
            }

            var groupHaveRole = GroupManager.IsGroupHasRole(group.Id, adminRole.Id);

            if (groupHaveRole == false)
            {
                GroupManager.SetGroupRoles(group.Id, new string[] { adminRole.Id });
            }
            return(Content("default Users , Groups  and Roles Creation success"));
        }