public HttpResponseMessage AddAsFriend(EncryptionForFriends listofFriends)
        {
            try
            {
                int flagint = -1;
                flagint = listofFriends.friendId;

                using (TransactionScope scope = new TransactionScope())
                {
                    using (var ctx = new MlaDatabaseEntities1())
                    {
                        int          fIdint         = Convert.ToInt32(listofFriends.friendId);
                        var          groupIdfromVar = ctx.groups.Where(x => x.userId == listofFriends.userId && x.groupType == 1).Select(x => x.groupNo).ToList();
                        int          grpfromint     = groupIdfromVar[0];
                        friendsTable fobj           = new friendsTable();
                        fobj.user_id    = listofFriends.userId;
                        fobj.friend_id  = fIdint;
                        fobj.Isaccepted = false;
                        fobj.groupNo    = grpfromint;
                        ctx.friendsTables.Add(fobj);

                        group_key grk1 = new group_key();
                        grk1.groupNo  = grpfromint;
                        grk1.groupKey = listofFriends.groupKey;
                        grk1.userId   = fIdint;
                        ctx.group_key.Add(grk1);

                        ctx.SaveChanges();
                    }
                    scope.Complete();
                }

                var response = Request.CreateResponse <int>(System.Net.HttpStatusCode.Created, flagint);
                return(response);
            }
            catch (Exception e)
            {
                var response = Request.CreateResponse <string>(System.Net.HttpStatusCode.BadRequest, "Error");
                return(response);
            }
        }
        public HttpResponseMessage AcceptFriendRequest(int userId, int friendId, string groupkey, string groupId)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    using (var ctx = new MlaDatabaseEntities1())
                    {
                        int          groupIDint = Convert.ToInt32(groupId);
                        friendsTable fobj       = new friendsTable();
                        fobj.user_id    = userId;
                        fobj.friend_id  = friendId;
                        fobj.Isaccepted = false;
                        fobj.groupNo    = groupIDint;
                        ctx.friendsTables.Add(fobj);
                        ctx.SaveChanges();
                        var lstfrndVar = (from ft in ctx.friendsTables
                                          where ft.user_id == friendId && ft.friend_id == userId
                                          select ft).Union(from std in ctx.friendsTables
                                                           where std.friend_id == friendId && std.user_id == userId
                                                           select std).ToList();
                        lstfrndVar.ForEach(c => c.Isaccepted = true);
                        group_key gkobj = new group_key();
                        gkobj.userId   = friendId;
                        gkobj.groupNo  = Convert.ToInt32(groupId);
                        gkobj.groupKey = groupkey;
                        var query = ctx.group_key.Add(gkobj);
                        ctx.SaveChanges();
                    }

                    scope.Complete();
                }
                var response = Request.CreateResponse <string>(System.Net.HttpStatusCode.Created, "Success");
                return(response);
            }
            catch (Exception e)
            {
                var response = Request.CreateResponse <string>(System.Net.HttpStatusCode.BadRequest, "Error");
                return(response);
            }
        }