Ejemplo n.º 1
0
        public IHttpActionResult AddKudosLog(AddKudosLogViewModel kudosLog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(Resources.Models.Kudos.Kudos.KudosifyModalError));
            }

            var kudosLogDto = _mapper.Map <AddKudosLogViewModel, AddKudosLogDTO>(kudosLog);

            SetOrganizationAndUser(kudosLogDto);
            try
            {
                if (kudosLog.TotalPointsPerReceiver.HasValue &&
                    _permissionService.UserHasPermission(GetUserAndOrganization(), AdministrationPermissions.Kudos))
                {
                    _kudosService.AddKudosLog(kudosLogDto, kudosLog.TotalPointsPerReceiver.Value);
                }
                else
                {
                    _kudosService.AddKudosLog(kudosLogDto);
                }

                return(Ok());
            }
            catch (UnauthorizedException) { return(Unauthorized()); }
            catch (ValidationException e) { return(BadRequestWithError(e)); }
        }
Ejemplo n.º 2
0
        public void Should_Return_If_User_Has_No_Permission()
        {
            var kudosLog = new AddKudosLogDTO
            {
                OrganizationId   = 2,
                PointsTypeId     = 1,
                UserId           = "testUserId",
                ReceivingUserIds = new List <string>()
                {
                    "testUserId"
                },
                MultiplyBy = 2,
                Comment    = "Comment"
            };

            Assert.Throws <KudosException>(() => _kudosService.AddKudosLog(kudosLog));
        }