Exemplo n.º 1
0
        public IActionResult ConfirmFriendAction(int InitiatorId, int DesiderId)
        {
            var userRelSelect = facebookDataContext.UserRelations.Where(usrRel => usrRel.InitiatorId == InitiatorId && usrRel.DesiderId == DesiderId).FirstOrDefault();

            if (userRelSelect == null)
            {
                return(Json(new { success = false }));
            }

            userRelSelect.SocialStatusId = (int)SocialStatuses.Friend;
            facebookDataContext.SaveChanges();
            //return RedirectToAction("index", searchStr);
            return(Json(new { success = true }));
        }
Exemplo n.º 2
0
        public IActionResult AddComment([FromBody] CommentPostDto commentPostDto)
        {
            if (commentPostDto == null || commentPostDto.CommentContent == null)
            {
                return(Json(new { statusCode = ResponseStatus.ValidationError, responseMessage = ValidationMessages.EmptyComment }));
            }
            User    user    = userData.GetUser(HttpContext);
            Comment comment = CommentDtoMapper.Map(commentPostDto, user.Id);

            facebookDataContext.Comments.Add(comment);
            try { facebookDataContext.SaveChanges(); }
            catch { return(Json(new { statusCode = ResponseStatus.Error })); }
            comment = facebookDataContext.Comments.Where(x => x.Id == comment.Id).Include("User.ProfilePhotos").FirstOrDefault();
            return(Json(new { statusCode = ResponseStatus.Success, responseMessage = HomePageDtoMapper.Map(comment, hostingEnvironment, user.Id), postId = comment.PostId }));
        }
Exemplo n.º 3
0
        public IActionResult DeletePost([FromQuery] int postId)
        {
            if (postId == 0)
            {
                return(Json(new { statusCode = ResponseStatus.ValidationError }));
            }
            User      user      = userData.GetUser(HttpContext);
            Post      post      = facebookDataContext.Posts.Where(x => x.Id == postId).FirstOrDefault();
            UsersPost usersPost = facebookDataContext.UsersPosts.Where(x => x.PostId == post.Id && x.IsCreator).FirstOrDefault();

            if (post == null || usersPost.UserId != user.Id)
            {
                return(Json(new { statusCode = ResponseStatus.ValidationError }));
            }
            post.IsDeleted = true;
            facebookDataContext.Posts.Update(post);
            try { facebookDataContext.SaveChanges(); }
            catch { return(Json(new { statusCode = ResponseStatus.Error })); }
            return(Json(new { statusCode = ResponseStatus.Success }));
        }
Exemplo n.º 4
0
        public UserDetails Create(UserDetails user)
        {
            var str = _context.UserDetails.SingleOrDefault(x => x.Email == user.Email);

            if (str != null)
            {
                return(str);
            }
            else
            {
                _context.UserDetails.Add(user);
                _context.SaveChanges();
                return(user);
            }
        }
Exemplo n.º 5
0
 public IActionResult rejectRequest([FromQuery] int?intiatorId, [FromQuery] int?deciderId)
 {
     if (intiatorId == null || deciderId == null)
     {
         return(Json(new { statusCode = ResponseStatus.ValidationError }));
     }
     try
     {
         var result = facebookDataContext.UserRelations.
                      Where(R => R.InitiatorId == intiatorId && R.DesiderId == deciderId && R.IsDeleted == false &&
                            R.SocialStatusId == (int)SocialStatuses.Request).FirstOrDefault();
         result.IsDeleted = true;
         facebookDataContext.SaveChanges();
         return(Json(new { statusCode = ResponseStatus.Success }));
     }
     catch
     {
         return(Json(new { statusCode = ResponseStatus.Error }));
     }
 }
Exemplo n.º 6
0
        public IActionResult Register([FromBody] UserRegisterDTO userRegisterDto)
        {
            User user = UserMapper.Map(userRegisterDto);

            FillEmptyFields(user);
            UserValidator validator = new UserValidator(ValidationMode.Create, db);
            var           result    = validator.Validate(user);

            if (!result.IsValid)
            {
                return(Json(new { statusCode = ResponseStatus.ValidationError, responseMessage = result.Errors }));
            }
            user.Password = Encription.Encrypt(user.Password, "SecretCode_hamed");
            db.Add(user);
            db.SaveChanges();
            string token = jwt.GenerateToken(user.Id);

            email.SendAccountActivationEmail(user.Email, "https://localhost:44340/Account/ActivateAccount/?token=" + token);
            return(Json(new { statusCode = ResponseStatus.Success, responseMessage = user.Id }));
        }