Ejemplo n.º 1
0
        public IHttpActionResult LogOut(Guid Id)
        {
            try
            {
                using (var ctx = new videoConEntities1())
                {
                    if (Id == null)
                    {
                        return(Ok("No Request Data"));
                    }

                    var loggedUser = ctx.loggedUsers
                                     .Where(a => a.userId == Id)
                                     .FirstOrDefault();
                    if (loggedUser == null)
                    {
                        return(Ok("User those not exit."));
                    }
                    var user = ctx.loggedUsers.Where(a => a.userId == Id).FirstOrDefault();

                    ctx.loggedUsers.Remove(user);
                    int result = ctx.SaveChanges();

                    if (result > 0)
                    {
                        return(Ok("Successfully Logged Off"));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
            return(Ok(" Save not completed"));
        }
Ejemplo n.º 2
0
        public IHttpActionResult EndCall(Guid id)
        {
            try
            {
                using (var ctx = new videoConEntities1())
                {
                    var EndCall = ctx.callInfoes
                                  .Where(a => a.ReceiverId == id || a.CallerId == id)
                                  .FirstOrDefault();
                    if (EndCall != null)
                    {
                        var updateCallHistory = ctx.CallHistories.Where(a => a.CallInfoId == EndCall.CallInfoId).FirstOrDefault();
                        updateCallHistory.TimeCallEnded = DateTime.Now;

                        ctx.callInfoes.Remove(EndCall);

                        var result = ctx.SaveChanges();



                        return(result > 0 ? Ok("Call Ended") : Ok("Call Not Ended"));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }

            return(Ok("Incorrect Id"));
        }
Ejemplo n.º 3
0
        public IHttpActionResult RegisterUser(RegisterUserModel User)
        {
            try
            {
                using (var ctx = new videoConEntities1())
                {
                    if (User == null)
                    {
                        return(Ok("No Request Data"));
                    }

                    var newUser = ctx.Users.Add(new User
                    {
                        UserId    = Guid.NewGuid(),
                        FirstName = User.FirstName,
                        LastName_ = User.LastName,
                        Email     = User.Email,
                        Password  = User.Password
                    });

                    int result = ctx.SaveChanges();
                    if (result == 1)
                    {
                        return(Ok(newUser));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
            return(Ok(" Save not completed"));
        }
Ejemplo n.º 4
0
 public IHttpActionResult GetUserProfile(Guid id)
 {
     try
     {
         using (var ctx = new videoConEntities1())
         {
             var user = (from u in ctx.Users
                         where u.UserId == id
                         select new
                         { u.LastName_,
                           u.FirstName,
                           u.Email }).FirstOrDefault();
             if (user == null)
             {
                 return(Ok("User with " + id + " id doesn't exist"));
             }
             else
             {
                 return(Ok(user));
             }
         }
     }
     catch (Exception ex)
     {
         throw ex.InnerException;
     }
 }
Ejemplo n.º 5
0
        public IHttpActionResult PickCall(Guid id)
        {
            using (var ctx = new videoConEntities1())
            {
                var PickCall = ctx.callInfoes
                               .Where(a => a.ReceiverId == id)
                               .FirstOrDefault();
                if (PickCall != null)
                {
                    try
                    {
                        PickCall.TimeCallPicked = DateTime.Now;
                        var callInfo = ctx.CallHistories.Add(new CallHistory
                        {
                            CallHistoryId = Guid.NewGuid(),
                            CallerId      = PickCall.CallerId.ToString(),
                            ReceiverId    = PickCall.ReceiverId.ToString(),
                            TimeCallBegan = DateTime.Now,
                            CallInfoId    = PickCall.CallInfoId
                        });
                        var result = ctx.SaveChanges();
                        if (result > 0)
                        {
                            var newDetails = (from m in ctx.callInfoes
                                              where id == m.ReceiverId
                                              join n in ctx.CallHistories on m.CallInfoId equals n.CallInfoId
                                              select new {
                                n.CallHistoryId,
                                n.CallerId,
                                n.CallInfoId,
                                n.ReceiverId,
                                n.TimeCallBegan,
                                m.SessionId,
                                m.Token
                            }).SingleOrDefault();

                            return(Ok(newDetails));
                        }

                        else
                        {
                            return(Ok("Call failed"));
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex.InnerException;
                    }
                }
            }

            return(Ok());
        }
Ejemplo n.º 6
0
        public IHttpActionResult IntiateCall(CallerViewModel data)
        {
            using (var ctx = new videoConEntities1())
            {
                var caller = ctx.Users
                             .Where(a => a.UserId == data.CallerId)
                             .FirstOrDefault();
                if (caller.UserId != null)
                {
                    try
                    {
                        var session = penTok.CreateSession();
                        var token   = session.GenerateToken();

                        var callInfo = ctx.callInfoes.Add(new callInfo
                        {
                            CallInfoId = Guid.NewGuid(),
                            CallerId   = data.CallerId,
                            ReceiverId = data.ReceiverId,
                            SessionId  = session.Id,
                            Token      = token
                        });

                        var newInfo = new callInfo();
                        newInfo.CallerId   = callInfo.CallerId;
                        newInfo.ReceiverId = callInfo.CallerId;
                        newInfo.SessionId  = callInfo.SessionId;
                        newInfo.CallInfoId = callInfo.CallInfoId;
                        newInfo.Token      = callInfo.Token;

                        var result = ctx.SaveChanges();
                        if (result == 1)
                        {
                            return(Ok(newInfo));
                        }
                        else
                        {
                            return(Ok("Call failed"));
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex.InnerException;
                    }
                }
            }

            return(Ok());
        }
Ejemplo n.º 7
0
        public IHttpActionResult IsUserAvailable(Guid id)
        {
            try
            {
                using (var ctx = new videoConEntities1())
                {
                    var user = (from u in ctx.loggedUsers
                                where u.userId == id
                                select new { u.email }).Any();

                    var CallInfo = (from u in ctx.callInfoes
                                    where u.ReceiverId == id && u.TimeCallPicked == null
                                    join r in ctx.Users on u.ReceiverId equals r.UserId
                                    join c in ctx.Users on u.CallerId equals c.UserId
                                    select new {
                        r.FirstName,
                        r.LastName_,
                        r.Email,
                        u.ReceiverId,
                        u.SessionId,
                        u.Token,
                        CallerId = u.CallerId,
                        CallerName = c.FirstName + " " + c.LastName_
                    })
                                   .FirstOrDefault();

                    if (user == false || CallInfo == null)
                    {
                        return(Ok("User isn't available"));
                    }
                    else
                    {
                        return(Ok(CallInfo));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
Ejemplo n.º 8
0
        public IHttpActionResult IsCallEnded(Guid id)
        {
            try
            {
                using (var ctx = new videoConEntities1())
                {
                    var recId = ctx.callInfoes
                                .Where(a => a.CallInfoId == id)
                                .FirstOrDefault();
                    var checkCallHistory = (from u in ctx.CallHistories
                                            where recId.CallInfoId == id
                                            select new { u.TimeCallEnded });

                    return(recId == null && checkCallHistory != null?Ok(true) : Ok(false));
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
        }
Ejemplo n.º 9
0
        public IHttpActionResult IsCallPicked(Guid id)
        {
            using (var ctx = new videoConEntities1())
            {
                var recId = ctx.callInfoes
                            .Where(a => a.ReceiverId == id)
                            .FirstOrDefault();
                if (recId.TimeCallPicked != null)
                {
                    try
                    {
                        var call = (from receiver in ctx.callInfoes
                                    where receiver.ReceiverId == id
                                    join callHistory in ctx.CallHistories on receiver.ReceiverId.ToString() equals callHistory.ReceiverId
                                    select new {
                            receiver.CallerId,
                            receiver.Token,
                            receiver.SessionId,
                            callHistory.TimeCallBegan
                        }).SingleOrDefault();


                        if (call != null)
                        {
                            return(Ok(call));
                        }
                        else
                        {
                            return(Ok("Call Has not been picked for this User"));
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex.InnerException;
                    }
                }
            }

            return(Ok("Incorrect Id"));
        }
Ejemplo n.º 10
0
        public IHttpActionResult Login(Models.LoginViewModel User)
        {
            try
            {
                using (var ctx = new videoConEntities1())
                {
                    if (User == null)
                    {
                        return(Ok("No Request Data"));
                    }

                    var loginUser = ctx.Users
                                    .Where(a => a.Email == User.Email)
                                    .FirstOrDefault();
                    if (loginUser == null)
                    {
                        return(Ok("User with this mail " + User.Email + " those not exit."));
                    }
                    var LoggedUser = ctx.loggedUsers.Add(new loggedUser
                    {
                        userId     = loginUser.UserId,
                        loggedTime = DateTime.Now,
                        email      = loginUser.Email
                    });
                    int result = ctx.SaveChanges();
                    if (result == 1)
                    {
                        return(Ok(LoggedUser));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
            return(Ok(" Save not completed"));
        }
Ejemplo n.º 11
0
 public IHttpActionResult AllUsers(Guid id)
 {
     try
     {
         using (var ctx = new videoConEntities1())
         {
             var CallInfo = (from u in ctx.Users
                             where u.UserId != id
                             select new { u.FirstName, u.LastName_, u.Email, u.UserId }).ToList();
             if (CallInfo == null)
             {
                 return(Ok("User isn't available"));
             }
             else
             {
                 return(Ok(CallInfo));
             }
         }
     }
     catch (Exception ex)
     {
         throw ex.InnerException;
     }
 }