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"));
        }
Example #2
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"));
        }
Example #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"));
        }
        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());
        }
        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());
        }
Example #6
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"));
        }