Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        public IHttpActionResult PostBlocked_Users(Blocked_Users blocked_Users)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Blocked_Users.Add(blocked_Users);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (Blocked_UsersExists(blocked_Users.user_id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = blocked_Users.user_id }, blocked_Users));
        }
        //user/block/1
        public ActionResult Block(int id)
        {
            HttpResponseMessage MYResponse = UserClient.GetAsync($"api/users/{Session["user_id"]}").Result;

            if (MYResponse.IsSuccessStatusCode)
            {
                User          Me           = MYResponse.Content.ReadAsAsync <User>().Result;
                Blocked_Users blocked_user = new Blocked_Users {
                    user_id = (int)Session["user_id"], user_block_id = id
                };
                HttpResponseMessage res = UserClient.PostAsJsonAsync($"api/blocked_users", blocked_user).Result;
                if (res.IsSuccessStatusCode)
                {
                    foreach (var item in Me.User_Friends)
                    {
                        if (item.user_friend_id == id)
                        {
                            HttpResponseMessage DeleteUserFriend = UserClient.DeleteAsync($"api/user_friends/{(int)Session["user_id"]},{id}").Result;
                        }
                    }
                    return(View());
                }
                else
                {
                    return(View("Error"));
                }
            }
            else
            {
                return(View("Error"));
            }
        }
        public ActionResult Search(String Searchstr)
        {
            //bool flag = false;

            HttpResponseMessage response = UserClient.GetAsync($"api/users/{(int)Session["user_id"]}/" + Searchstr).Result;

            if (response.IsSuccessStatusCode)
            {
                List <User> users = response.Content.ReadAsAsync <List <User> >().Result;

                HttpResponseMessage MyResponse = UserClient.GetAsync($"api/users/{Session["user_id"]}").Result;
                User        me            = MyResponse.Content.ReadAsAsync <User>().Result;
                List <User> Unblockeduser = new List <User>();
                foreach (var item in users)
                {
                    Blocked_Users blockeduser = me.Blocked_Users.FirstOrDefault(p => p.user_block_id == item.user_id);
                    if (blockeduser == null)
                    {
                        Unblockeduser.Add(item);
                    }
                }
                if (Unblockeduser.Count <= 0)
                {
                    return(View("NoResult"));
                }
                else
                {
                    return(View("SearchResult", Unblockeduser));
                }
            }
            else
            {
                return(View("NoResult"));
            }
        }
Exemplo n.º 5
0
        public void CreateBlocked(BlockedUsersDTO userDto)
        {
            Blocked_Users user = new Blocked_Users
            {
                User_ID    = userDto.User_ID,
                Blocked_ID = userDto.Blocked_ID,
            };

            this.Database.Blocked_Users.Create(user);
            this.Database.Save();
        }
Exemplo n.º 6
0
        public IHttpActionResult GetBlocked_Users(int id)
        {
            Blocked_Users blocked_Users = db.Blocked_Users.Find(id);

            if (blocked_Users == null)
            {
                return(NotFound());
            }

            return(Ok(blocked_Users));
        }
Exemplo n.º 7
0
        public IHttpActionResult DeleteBlocked_Users(int id)
        {
            Blocked_Users blocked_Users = db.Blocked_Users.Find(id);

            if (blocked_Users == null)
            {
                return(NotFound());
            }

            db.Blocked_Users.Remove(blocked_Users);
            db.SaveChanges();

            return(Ok(blocked_Users));
        }
Exemplo n.º 8
0
        public IHttpActionResult DeleteBlocked_Users(int UserId, int MyID)
        {
            Blocked_Users blocked_Users = db.Blocked_Users.FirstOrDefault(p => p.user_id == MyID && p.user_block_id == UserId);

            if (blocked_Users == null)
            {
                return(NotFound());
            }

            db.Blocked_Users.Remove(blocked_Users);
            db.SaveChanges();

            return(Ok(blocked_Users));
        }