示例#1
0
        public async Task <IDataResult <IList <UserTaskDto> > > GetAllUserTasksForLoggedInUser()
        {
            var userId = SecuredClaimer.GetUserId();

            if (string.IsNullOrEmpty(userId))
            {
                return(new ErrorDataResult <IList <UserTaskDto> >(Messages.AuthorizationDenied));
            }

            var list    = _userTaskDal.GetList(x => x.UserId == Convert.ToInt32(userId), t => t.TaskType);
            var listDto = _mapper.Map <IList <UserTaskDto> >(list);

            return(new SuccessDataResult <IList <UserTaskDto> >(listDto));
        }
示例#2
0
        public async Task <IResult> BanUserManually(User user, bool state = true)
        {
            var adminInfo = await GetUserById(Convert.ToInt32(SecuredClaimer.GetUserId()));

            if (adminInfo.Success)
            {
                user.IsBanned    = state;
                user.UpdatedDate = DateTime.Now;
                var result = await Update(user);

                return(result);
            }

            return(new ErrorResult(Messages.AuthorizationDenied));
        }
示例#3
0
        public async Task <IDataResult <UserDetailsDto> > GetMe()
        {
            var userId = SecuredClaimer.GetUserId();

            if (string.IsNullOrEmpty(userId))
            {
                return(new ErrorDataResult <UserDetailsDto>());
            }

            var user = _userDal.GetSingle(x => x.Id.Equals(Convert.ToInt32(userId)));

            if (user == null)
            {
                return(new ErrorDataResult <UserDetailsDto>());
            }

            var userDetails = _userDal.GetDetailsDto(user);

            return(new SuccessDataResult <UserDetailsDto>(_mapper.Map <UserDetailsDto>(user)));
        }
示例#4
0
        public async Task <IResult> Add(params UserTask[] userTasks)
        {
            var userId = Convert.ToInt32(SecuredClaimer.GetUserId());

            foreach (var userTask in userTasks)
            {
                userTask.UserId      = userId;
                userTask.CreatedDate = DateTime.UtcNow;
                userTask.UpdatedDate = null;
                userTask.EndDate     = userTask.EndDate == DateTime.MinValue ? GetCalculatedEndDate(userTask.StartDate, userTask.TaskTypeId) : userTask.EndDate;
            }

            _userTaskDal.AddRange(userTasks);

            if (await _userTaskDal.SaveChangesAsync() > 0)
            {
                return(new SuccessResult());
            }

            return(new ErrorResult());
        }
示例#5
0
        public async Task <IActionResult> Logout()
        {
            try
            {
                var result = await _authService.Logout();

                if (result.Success)
                {
                    _logger.LogInformation("@{userId} logged out.", SecuredClaimer.GetUserId());

                    return(StatusCode(StatusCodes.Status200OK));
                }

                return(StatusCode(StatusCodes.Status400BadRequest, result.Message));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }