public IHttpActionResult PostUsersGroups(GroupBindingModel groupBM)
        {
            if (groupBM.UserGroupList == null)
            {
                return(BadRequest());
            }

            var identity = (ClaimsIdentity)User.Identity;
            IEnumerable <Claim> claims = identity.Claims;
            var userId = int.Parse(claims.Where(c => c.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value);


            groupBM.UserGroupList.Remove(groupBM.UserGroupList.Where(ug => ug.UserId == userId).FirstOrDefault());
            groupBM.UserId = userId;

            var userGroupList = AutoMapper.Mapper.Map <List <UserGroupBindingModel>, List <UserGroup> >(groupBM.UserGroupList);


            try
            {
                userGroupService.AddUserGroup(userGroupList, groupBM.Name, userId);
                unitOfWork.Commit();
            }
            catch (Exception e)
            {
                if (ModelState.Count() == 0)
                {
                    ModelState.AddModelError("", "Postoji grupa sa unetim imenom");
                }
                return(BadRequest(ModelState));
            }

            return(Ok());
        }
示例#2
0
        public IActionResult AddUserGroup([FromBody] UserGroupInputDto input)
        {
            var result = _service.AddUserGroup(input);

            return(AddResponse(result));
        }