public async Task <ActionResult> GetUserList([FromQuery] UserParams userParams) { userParams.PageNumber = userParams.PageNumber <= 0 ? 1 : userParams.PageNumber; userParams.PageSize = userParams.PageSize <= 0 ? 5 : userParams.PageSize; var UserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); List <UsersDto> listUserDto = new List <UsersDto>(); listUserDto = await objDattingDAL.GetUserList(); listUserDto = listUserDto.OrderByDescending(x => x.LastActive).ToList(); var currentUser = listUserDto.FirstOrDefault(x => x.id == UserId); userParams.UserId = UserId; if (!string.IsNullOrEmpty(userParams.Gender) && userParams.Gender != "ALL") { listUserDto = listUserDto.Where(x => x.Gender == userParams.Gender).ToList(); } if (userParams.MinAge != 18 || userParams.MaxAge != 99) { var MinDob = DateTime.Today.AddYears(-userParams.MaxAge - 1); var MaxDob = DateTime.Today.AddYears(-userParams.MinAge); listUserDto = listUserDto.Where(x => x.DateOfBirth >= MinDob && x.DateOfBirth <= MaxDob).ToList(); } if (!string.IsNullOrEmpty(userParams.OrderBy)) { switch (userParams.OrderBy) { case "created": listUserDto = listUserDto.OrderByDescending(x => x.Created).ToList(); break; default: listUserDto = listUserDto.OrderByDescending(x => x.LastActive).ToList(); break; } } var PageListUser = PagedList <UsersDto> .Create(listUserDto.AsQueryable(), userParams.PageNumber, userParams.PageSize); Response.AddPagination(PageListUser.CurrentPage, PageListUser.PageSize, PageListUser.TotalCount, PageListUser.TotalPages); return(Ok(PageListUser)); }
public async Task <IActionResult> AddLikes([FromBody] LikesDto objLikeDto) { var userId = objLikeDto.LikerId; if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var likeList = await objLikesDAL.GetLike(); var like = likeList.FirstOrDefault(x => x.LikerId == objLikeDto.LikerId && x.LikeeId == objLikeDto.LikeeId); if (like != null) { return(BadRequest("You already like this user")); } var user = await objDattingDAL.GetUserList(); if (!user.Exists(x => x.id == userId)) { return(NotFound()); } var likesId = await objLikesDAL.AddLikes(objLikeDto); return(Ok()); }
public async Task <IActionResult> AddPhotoForUser(int UserId, [FromForm] PhotoCreationDto ObjPhotoCreationDto) { List <UsersDto> listUserDto = new List <UsersDto>(); UsersDto objUserDto = new UsersDto(); PhotoDto objPhotoDto = new PhotoDto(); var file = ObjPhotoCreationDto.File; var uploadResult = new ImageUploadResult(); if (UserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } listUserDto = await objDattingDAL.GetUserList(); objUserDto = listUserDto.FirstOrDefault(U => U.id == UserId); if (file.Length > 0) { using (var stream = file.OpenReadStream()) { var uploadsParams = new ImageUploadParams() { File = new FileDescription(file.Name, stream), Transformation = new Transformation().Width(500).Height(500).Crop("fill").Gravity("face") }; uploadResult = _cloudinary.Upload(uploadsParams); } } ObjPhotoCreationDto.Url = uploadResult.Uri.ToString(); ObjPhotoCreationDto.PublicId = uploadResult.PublicId; objPhotoDto.PublicId = ObjPhotoCreationDto.PublicId; objPhotoDto.IsMain = false; objPhotoDto.Description = ObjPhotoCreationDto.Description; objPhotoDto.AddDate = ObjPhotoCreationDto.DateAdded; objPhotoDto.url = ObjPhotoCreationDto.Url; objPhotoDto.FkUserId = UserId; if (!objUserDto.Photos.Any(x => x.IsMain)) { objPhotoDto.IsMain = true; } PhotoDto objPhoto = new PhotoDto(); objPhoto = await objPhotoDAL.InsertPhoto(objPhotoDto); if (objPhoto != null && objPhoto.Id > 0) { return(Ok(objPhoto)); } return(BadRequest("Could not add the photo")); }