Пример #1
0
        public async Task <ResponseMessage> SetAsBookmarked([FromBody] BookmarkViewModel model)
        {
            //get current user from jwt token
            var userName = HttpContext?.User.Claims.FirstOrDefault(c => c.Type == System.Security.Claims.ClaimTypes.NameIdentifier).Value;
            var user     = await _userManager.FindByNameAsync(userName);

            var Bookmarked = _appUserService.CheckIfIsBookmarkedJob(user.Id, model.Id);

            if (model.IsBookmarked == true)
            {
                if (Bookmarked)
                {
                    return new ResponseMessage {
                               Message = "Job has been already bookmarked", IsSuccess = false
                    }
                }
                ;

                _appUserService.BookmarkedJob(new BookmarkedJobViewModel {
                    AppUserId = user.Id, JobId = model.Id
                });
                return(new ResponseMessage {
                    IsSuccess = true, Message = "Job is bookmarked"
                });
            }
            else
            {
                if (!Bookmarked)
                {
                    return new ResponseMessage {
                               Message = "Job is not bookmarked", IsSuccess = false
                    }
                }
                ;

                _appUserService.UnBookmarkedJob(new BookmarkedJobViewModel {
                    AppUserId = user.Id, JobId = model.Id
                });
                return(new ResponseMessage {
                    IsSuccess = true, Message = "Job is un bookmarked"
                });
            }
        }