public void Delete(int id)
 {
     try
     {
         var post = context.Posts.Find(id);
         if (post == null)
         {
             return;
         }
         var postLikes = context.Likes.Where(l => l.PostId == id);
         foreach (var like in postLikes)
         {
             like.IsLiked = false;
             context.Entry(like).State = EntityState.Modified;
         }
         var postComments = context.Comments.Where(c => c.PostId == id);
         foreach (var comment in postComments)
         {
             comment.IsDeleted            = true;
             context.Entry(comment).State = EntityState.Modified;
         }
         post.IsDeleted            = true;
         context.Entry(post).State = EntityState.Modified;
         context.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #2
0
        public IHttpActionResult PutComment(int id, Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != comment.comment_id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutUser([FromUri] int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.user_id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(user));
        }
        public IHttpActionResult PutGroup_Posts(int id, Group_Posts group_Posts)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != group_Posts.post_id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Group_PostsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #5
0
        public IHttpActionResult PutBlocked_Users(int id, Blocked_Users blocked_Users)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != blocked_Users.user_id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Blocked_UsersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public void Create(DtoConnection conn)
        {
            Connection Econn = new Connection();

            Econn.CreatedDate = conn.CreatedDate;
            Econn.IsActive    = conn.IsActive;
            Econn.IsDeleted   = conn.IsDeleted;
            Econn.UserIdOne   = conn.UserIdOne;
            Econn.UserIdTwo   = conn.UserIdTwo;
            context.connections.Add(Econn);
            context.SaveChanges();
        }
Пример #7
0
 public void Insert(Like t)
 {
     try
     {
         context.Likes.Add(t);
         context.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void Delete(string id)
 {
     try
     {
         var user = context.Users.Find(id);
         if (user == null)
         {
             return;
         }
         user.IsDeleted = true;
         context.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #9
0
 public void Delete(string id)
 {
     try
     {
         var friendRequest = context.FriendRequests.Find(id);
         if (friendRequest == null)
         {
             return;
         }
         context.Remove(friendRequest);
         context.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void DeleteById(int id)
 {
     try
     {
         var comment = context.Comments.FirstOrDefault(c => c.CommentId == id);
         if (comment == null)
         {
             return;
         }
         comment.IsDeleted = true;
         context.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public IActionResult CreateAccount(string firstname, string lastname, string tel_email, string pswrd, string gender, string day, string month, string year)
        {
            User user = new User();

            user.FirstName = firstname;
            user.LastName  = lastname;
            user.Password  = pswrd;
            user.Gender    = gender;

            if (day != null && month != null && year != null)
            {
                DateTime date = new DateTime();
                date.AddYears(Convert.ToInt32(year));
                date.AddMonths(Convert.ToInt32(month));
                date.AddDays(Convert.ToInt32(day));
                user.BirthDate = date;
            }

            if (tel_email.Contains("@"))
            {
                user.Email = tel_email;
            }
            else
            {
                user.PhoneNumber = tel_email;
            }
            Image image = new Image();

            if (gender == "erkek" || gender == "özel")
            {
                image.ImageLink = "iconfinder_user_male2_172626.png";
            }
            else if (gender == "kadın")
            {
                image.ImageLink = "iconfinder_user_female2_172622.png";
            }

            context.Users.Add(user);
            context.SaveChanges();
            user.ProfilePhoto = image;
            user.Images.Add(image);
            context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Пример #12
0
        public IActionResult Likeoperation(Like entity)
        {
            var sorgu = context.Likes.Where(x => x.PostId == entity.PostId && x.UserId == entity.UserId).FirstOrDefault();

            if (sorgu == null)
            {
                entity.IsActive = true;

                context.Likes.Add(entity);
                context.SaveChanges();
            }
            else
            {
                sorgu.IsActive = true;
                context.Likes.Update(sorgu);
                context.SaveChanges();
            }
            return(Json(true));
        }
        public void AddComment(DtoComment commentDto)
        {
            Comment comment = new Comment();

            comment.UserId       = commentDto.UserId;
            comment.PostId       = commentDto.PostId;
            comment.Description  = commentDto.Description;
            comment.CommentCount = commentDto.CommentCount;
            comment.IsDeleted    = commentDto.IsDeleted;

            db.comments.Add(comment);
            db.SaveChanges();
        }
Пример #14
0
        public async Task SendMessage(string user, string friend, string message)
        {
            Message msg = new Message();

            msg.Content    = message;
            msg.SendDate   = DateTime.Now;
            msg.FriendId   = Convert.ToInt32(friend);
            msg.FriendUser = context.Users.Find(Convert.ToInt32(friend));

            context.Users.Find(Convert.ToInt32(user)).Messages.Add(msg);
            context.SaveChanges();

            await Clients.All.SendAsync("ReceiveMessage", user, message);
        }
Пример #15
0
        public void CreatePost(DtoPost post)
        {
            Post postentity = new Post();

            postentity.CommentCount = post.CommentCount;
            postentity.Description  = post.Description;
            postentity.LikeCount    = post.LikeCount;
            postentity.Photo        = post.Photo;
            postentity.Replyto      = post.Replyto;
            postentity.UserID       = post.UserID;
            postentity.CreatedDate  = DateTime.Now;
            postentity.isactive     = true;
            postentity.isdelete     = false;

            fbcontext.Post.Add(postentity);
            fbcontext.SaveChanges();
        }
Пример #16
0
        public IActionResult SharePost(string content, int userid)
        {
            Post post = new Post();

            post.Content    = content;
            post.CreateDate = DateTime.Now;

            var user = context.Users.Find(userid);

            post.User   = user;
            post.UserId = user.UserId;

            user.Posts.Add(post);
            context.SaveChanges();

            int id = userid;

            return(RedirectToAction("Index", "Main", new { id }));
        }
Пример #17
0
        public void Create(DtoUser dtouser)
        {
            _user.FullName        = dtouser.FullName;
            _user.Username        = dtouser.Username;
            _user.Password        = dtouser.Password;
            _user.LiveCity        = dtouser.LiveCity;
            _user.Homeland        = dtouser.Homeland;
            _user.ProfilPhoto     = dtouser.ProfilPhoto;
            _user.BackgorundImage = dtouser.BackgroundImage;
            _user.PhoneNumber     = dtouser.PhoneNumber;
            _user.CreatedDate     = DateTime.Now;
            _user.IsActive        = true;
            _user.IsDeleted       = false;
            _user.Private         = true;

            context.Users.Add(_user);
            context.SaveChanges();
        }
Пример #18
0
 public ActionResult Create(Post p)
 {
     db.Posts.Add(p);
     db.SaveChanges();
     return(Json(p.PostId));
 }