Esempio n. 1
0
        public ActionResult Login(string loginEmail, string loginPassword, string returnUrl)
        {
            if (string.IsNullOrEmpty(loginEmail) || string.IsNullOrEmpty(loginPassword))
            {
                ViewBag.message = "Kullanıcı adı veya şifre boş bırakılamaz";
                return(RedirectToAction("Index", "Home"));
            }
            Task <User> userTask = UserManager.FindAsync(loginEmail, loginPassword);
            var         user     = userTask.Result;

            if (user != null)
            {
                HttpContext.GetOwinContext().Authentication.SignOut();
                var ident = new ClaimsIdentity(
                    new[] {
                    // adding following 2 claim just for supporting default antiforgery provider
                    new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                    new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"),

                    new Claim(ClaimTypes.Name, loginEmail),
                    new Claim(ClaimTypes.PrimarySid, user.Id.ToString()),
                    // optionally you could add roles if any
                    new Claim(ClaimTypes.Role, "User"),
                },
                    DefaultAuthenticationTypes.ApplicationCookie);

                HttpContext.GetOwinContext().Authentication.SignIn(
                    new AuthenticationProperties {
                    IsPersistent = true
                }, ident);
                string decodedUrl = "";
                if (!string.IsNullOrEmpty(returnUrl))
                {
                    decodedUrl = Server.UrlDecode(returnUrl.Replace("ReturnUrl=", ""));
                }
                if (user.IsFirstLogin)
                {
                    var newObjUser = _db.Users.Find(user.Id);
                    _db.Users.Attach(newObjUser);
                    newObjUser.IsFirstLogin = false;
                    _db.Entry(newObjUser).Property(e => e.IsFirstLogin).IsModified = true;

                    _db.SaveChanges();
                    return(RedirectToAction("InterestCategories", "Users"));
                }
                if (Url.IsLocalUrl(decodedUrl))
                {
                    return(Redirect(decodedUrl));
                }
                else
                {
                    return(RedirectToAction("Newsfeed", "Home"));
                }
            }
            else
            {
                ViewBag.message = "Kullanıcı adı veya şifre boş bırakılamaz";
                return(RedirectToAction("Index", "Home"));
            }
        }
Esempio n. 2
0
        public ActionResult AddCommentToPost(int? postid,string comment)
        {
            if (postid == null) return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            var post = _db.PostById((int)postid);
            if(post ==null ) return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            var user = GetUserModel();
            var userComment = new PostComments { UserId = user.Id,PostID = (int)postid,PostComment = comment,PostCommentDate = DateTime.Now};
            _db.UsersLastMoves.Add(new UsersLastMoves { MoveDate = DateTime.Now, UserId = user.Id, UsersLastMoveText =" bir gönderiye yorum yaptı.",UsersMoveLink = "/users/index/"+post.UserId+"#post"+post.PostID});
            _db.PostComments.Add(userComment);
            try
            {
                _db.SaveChanges();
                return Json(1);
            }
            catch
            {
                return Json(0);
            }

        }
 public void UpdateNotification(List <UserNotifications> notifyList)
 {
     using (var context = new ScoutUpDB())
     {
         foreach (var notify in notifyList)
         {
             notify.UserNotificationsRead = true;
             context.Entry(notify).State  = EntityState.Modified;
         }
         context.SaveChanges();
     }
 }
        public UserNotifications AddNotification(string userid, string message, string notifiyDirection, string notifyLink)
        {
            var notify = new UserNotifications()
            {
                UserId = userid,
                UserNotificationsMessage = message,
                UserNotificationsDate    = DateTime.Now,
                UserNotificationsRead    = false,
                NotificationLink         = notifyLink
            };

            using (var context = new ScoutUpDB())
            {
                context.UserNotifications.Add(notify);
                context.SaveChanges();
            }
            return(notify);
        }
Esempio n. 5
0
        public ActionResult LikePost(int? id)
        {
            if (id == null) return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            var post = _db.PostById((int)id);
            
            var user = GetUserModel();
            var isLiked = _db.PostLikes.Where(e => e.UserId == user.Id).FirstOrDefault(e => e.PostID == id);
            if (isLiked != null)
            {
                    _db.PostLikes.Attach(isLiked);
                    _db.Entry(isLiked).State = EntityState.Deleted;
                    _db.SaveChanges();
                    //NotificationRepository repo=new NotificationRepository();
                    //repo.AddNotification(post.UserId,user.UserFirstName+ " " + user.UserSurname +" gönderini beğendi");
                    return Json(new { success = true,liked = false, likes = _db.PostById((int)id).PostLikes.Count }, JsonRequestBehavior.AllowGet);
                }
            var postLike = new PostLikes
            {
                UserId = user.Id,
                PostID = (int) id,
                IsLiked = true
            };

            try
            {
                using (var context = new ScoutUpDB())
                {
                    context.PostLikes.Add(postLike);
                    context.UsersLastMoves.Add(new UsersLastMoves { MoveDate = DateTime.Now, UserId = user.Id, UsersLastMoveText =" bir gönderiyi beğendi.", UsersMoveLink = "/users/index/" + post.UserId + "#post" + post.PostID });
                    context.SaveChanges();
                    return Json(new { success = true,liked=true,likes =context.PostById((int)id).PostLikes.Count },JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception ex)
            {

                return Json(new { success = false, error = true, message = ex.InnerException.ToString() },JsonRequestBehavior.AllowGet);
            }
        }
Esempio n. 6
0
        private LikePost SaveLike(int?postid, string userid)
        {
            var post = _db.Posts.Find(postid);

            var user    = _db.Users.Find(userid);
            var isLiked = _db.PostLikes.Where(e => e.UserId == user.Id).FirstOrDefault(e => e.PostID == postid);

            if (isLiked != null)
            {
                using (var context = new ScoutUpDB())
                {
                    _db.Dispose();

                    context.PostLikes.Attach(isLiked);
                    context.Entry(isLiked).State = EntityState.Deleted;
                    context.SaveChanges();
                    return(new LikePost
                    {
                        LikeCount = post.PostLikes.Count,
                        Liked = false,
                        PostId = (int)postid
                    });
                }
            }

            var postLike = new PostLikes
            {
                UserId  = user.Id,
                PostID  = (int)postid,
                IsLiked = true
            };

            try
            {
                using (var context = new ScoutUpDB())
                {
                    context.PostLikes.Add(postLike);
                    context.UsersLastMoves.Add(new UsersLastMoves {
                        MoveDate = DateTime.Now, UserId = user.Id, UsersLastMoveText = " bir gönderiyi beğendi.", UsersMoveLink = "/users/index/" + post.UserId + "#post" + post.PostID
                    });
                    context.SaveChanges();
                    return(new LikePost
                    {
                        LikeCount = post.PostLikes.Count,
                        Liked = true
                        , PostId = (int)postid
                    });
                }
            }
            catch (Exception ex)
            {
                return(new LikePost
                {
                    LikeCount = post.PostLikes.Count,
                    Liked = false
                });
            }
            //    var postId = int.Parse(id);
            //    var baseContext = Context.Request.GetHttpContext();
            //    var postRepository = _db;
            //    var item = _db.Posts.Find(postId);
            //    var liked = new PostLike
            //    {
            //        IPAddress = baseContext.Request.UserHostAddress,
            //        PostId = item.Id,
            //        UserAgent = baseContext.Request.UserAgent,
            //        UserLike = true
            //    };
            //    var dupe = item.PostLikes.FirstOrDefault(e => e.IPAddress == liked.IPAddress);
            //    if (dupe == null)
            //    {
            //        item.PostLikes.Add(liked);
            //    }
            //    else
            //    {
            //        dupe.UserLike = !dupe.UserLike;
            //    }
            //    postRepository.SaveChanges();
            //    var post = postRepository.GetById(postId);

            //    return new LikePost
            //    {
            //        LikeCount = post.PostLikes.Count(e => e.UserLike)
            //    };
            //}
        }