コード例 #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"));
            }
        }
コード例 #2
0
        public async Task <IHttpActionResult> PutPost(int id, Post post)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != post.PostID)
            {
                return(BadRequest());
            }

            db.Entry(post).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public async Task <ActionResult> Edit([Bind(Include = "CategoryItemID,CategoryID,CategoryItemName,CategoryItemPhoto")] CategoryItems categoryItems)
        {
            if (ModelState.IsValid)
            {
                db.Entry(categoryItems).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", categoryItems.CategoryID);
            return(View(categoryItems));
        }
コード例 #4
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();
     }
 }
コード例 #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);
            }
        }
コード例 #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)
            //    };
            //}
        }