Exemplo n.º 1
0
        public static string CallState(List <string> param)
        {
            //kto
            //do kogo
            //data rozpoczecia
            //czas trwania //00:00:00 -> null

            string login1 = param[0];
            string login2 = param[1];

            using (var ctx = new SecConvDBEntities())
            {
                var SenderID = ctx.Users.Where(x => x.Login == login1).Select(x => x.UserID).FirstOrDefault();
                if (SenderID != 0)
                {
                    var ReceiverID = ctx.Users.Where(x => x.Login == login2).Select(x => x.UserID).FirstOrDefault();
                    if (ReceiverID != 0)
                    {
                        var history = new Histories();
                        history.UserSenderID   = SenderID;
                        history.UserReceiverID = ReceiverID;
                        //yyyy-MM-dd-HH:mm:ss
                        history.Start = DateTime.ParseExact(param[2], "yyyy-MM-dd-HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

                        //HH:mm:ss
                        //TimeSpan duration = TimeSpan.Parse(param[3]);
                        history.Duration = new DateTime().Add(TimeSpan.Parse(param[3]));
                        try
                        {
                            ctx.Histories.Add(history);
                            ctx.SaveChanges();
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            return(Fail());
                        }
                    }
                    else
                    {
                        return(Fail());
                    }
                }
                else
                {
                    return(Fail());
                }
            }
            return(OK());
        }
Exemplo n.º 2
0
        public static string LogOut(List <string> param)
        {
            string login = param[0];

            using (var ctx = new SecConvDBEntities())
            {
                var userToLogOut = ctx.Users.Where(x => x.Login == login).FirstOrDefault();
                if (userToLogOut != null)
                {
                    userToLogOut.LastLogoutDate = DateTime.Now;
                    try
                    {
                        Program.onlineUsers.Remove(userToLogOut.UserID); //delete from dictionary
                        ctx.Entry(userToLogOut).State = System.Data.Entity.EntityState.Modified;
                        ctx.SaveChanges();
                        //find people who have friend that is logged in
                        var friends = ctx.Friends.Where(x => x.UserID2 == userToLogOut.UserID).Select(x => x.UserID1);
                        //wyszukaj znajomych w slowniku online i dodaj/zmień w słowniku adres IP
                        foreach (var item in friends)
                        {
                            if (Program.onlineUsers.ContainsKey(item))
                            {
                                Program.onlineUsers[item].friendWithChangedState[login] = "0";
                            }
                        }
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        return(Fail());
                    }
                }
                else
                {
                    return(Fail());
                }
            }
            return(OK());
        }
Exemplo n.º 3
0
        public static string DelFriend(List <string> param)
        {
            string login1 = param[0]; //logged in user
            string login2 = param[1];

            using (var ctx = new SecConvDBEntities())
            {
                var userLoggedInID1 = ctx.Users.Where(x => x.Login == login1).Select(x => x.UserID).FirstOrDefault();
                if (userLoggedInID1 != 0)
                {
                    var user1Friend = ctx.Users.Where(x => x.Login == login2).Select(x => new { x.UserID, x.Login }).FirstOrDefault();
                    if (user1Friend.UserID != 0)
                    {
                        var friend = ctx.Friends.Where(x => x.UserID1 == userLoggedInID1 && x.UserID2 == user1Friend.UserID).FirstOrDefault();
                        ctx.Entry(friend).State = System.Data.Entity.EntityState.Deleted;
                        try
                        {
                            ctx.SaveChanges();
                            Program.onlineUsers[userLoggedInID1].friendWithChangedState.Remove(user1Friend.Login);
                        }
                        catch (DbUpdateConcurrencyException)
                        {
                            return(Fail());
                        }
                    }
                    else
                    {
                        return(Fail());
                    }
                }
                else
                {
                    return(Fail());
                }
            }
            return(OK());
        }