Example #1
0
        public async Task <IActionResult> DeleteFriend(string id)
        {
            if (id == null)
            {
                return(BadRequest());
            }
            var friend = await friendRepo.DeleteFriend(_context, id);

            if (friend == null)
            {
                return(NotFound());
            }
            return(Ok());
            //if (id == null) return BadRequest();

            //string myId = id.Split('|')[0];
            //string hisId = id.Split('|')[1];

            //var friend = await _context.Friends.Where(x => x.deleted == false)
            //    .Include(messages => messages.messages)
            //    .FirstOrDefaultAsync(i => i.myId == myId && i.hisId == hisId);

            //if (friend == null) return BadRequest();
            //if (friend.deleted == true) return BadRequest();

            //foreach (var message in friend.messages)
            //{
            //    message.deleted = true;
            //    _context.Entry(message).State = EntityState.Modified;
            //}

            //friend.deleted = true;
            //_context.Entry(friend).State = EntityState.Modified;

            //var friend1 = await _context.Friends.Where(x => x.deleted == false)
            //    .Include(messages => messages.messages)
            //    .FirstOrDefaultAsync(i => i.myId == hisId && i.hisId == myId);

            //if (friend1 == null) return BadRequest();
            //if (friend1.deleted == true) return BadRequest();

            //foreach (var message in friend1.messages)
            //{
            //    message.deleted = true;
            //    _context.Entry(message).State = EntityState.Modified;
            //}

            //friend1.deleted = true;
            //_context.Entry(friend1).State = EntityState.Modified;

            //await _context.SaveChangesAsync();

            //return Ok();
        }
 public ActionResult Delete(string Id)
 {
     _db.DeleteFriend(Id, User.Identity.GetUserId());
     return(View("List", _db.getAll()));
 }