Пример #1
0
        public IHttpActionResult DeleteSessions(CustomersSessions strSession)
        {
            SessionIDManager  manager = new SessionIDManager();
            CustomersSessions session = m_db.Sessions.SingleOrDefault(x => x.SessionId == strSession.SessionId);

            bool isExpired = doesSessionExpired(strSession);

            if (isExpired)
            {
                manager.RemoveSessionID(HttpContext.Current);
                m_db.Sessions.Remove(session);
                m_db.SaveChanges();
                return(BadRequest("Your session expierd"));
            }

            if (manager.Validate(strSession.SessionId))
            {
                Customer customer = m_db.Customers.SingleOrDefault(x => x.Id == session.CustomerId);

                if (session == null || customer == null)
                {
                    return(BadRequest());
                }
                customer.LastSeenDate = session.SessionDate;
                customer.LastSeenTime = session.SessionTime;

                manager.RemoveSessionID(HttpContext.Current);
                m_db.Sessions.Remove(session);
                m_db.SaveChanges();

                //return Ok(session);
                return(Ok("session deleted succesfully"));
            }
            return(BadRequest());
        }
Пример #2
0
        public bool doesSessionExpired(CustomersSessions strSession)
        {
            bool isExpired            = false;
            CustomersSessions session = m_db.Sessions.SingleOrDefault(x => x.SessionId == strSession.SessionId);

            char[] delimiterChars = { ':', '/' };

            string[] date = session.SessionDate.Split(delimiterChars);
            string[] Time = session.SessionTime.Split(delimiterChars);

            DateTime CurrentTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
                                                DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);

            DateTime sessionTime = new DateTime(Int32.Parse(date[2]), Int32.Parse(date[1]),
                                                Int32.Parse(date[0]), Int32.Parse(Time[0]), Int32.Parse(Time[1]), Int32.Parse(Time[2]));

            int timeBetween = CurrentTime.Subtract(sessionTime).Minutes;

            if (timeBetween > 20)
            {
                isExpired = true;
            }
            else
            {
                isExpired = false;
            }
            return(isExpired);
        }
        public HttpResponseMessage DeleteSessions(long id)
        {
            CustomersSessions session  = m_db.Sessions.Find(id);
            Customer          customer = m_db.Customers.SingleOrDefault(x => x.Id == session.CustomerId);

            if (session == null || customer == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "invalid"));
            }

            customer.lastseenDate = session.SessionDate;
            customer.lastseenTime = session.SessionTime;

            m_db.Sessions.Remove(session);
            m_db.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Пример #4
0
        public HttpResponseMessage CustomerConfirmation(string email, string password)
        {
            if (string.IsNullOrEmpty(email) && string.IsNullOrEmpty(password))
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, "user name or password is invalid"));
            }

            if (email == "*****@*****.**" && password == "theone123456")
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "This is Admin"));
            }
            else
            {
                Customer          customer   = m_db.Customers.SingleOrDefault(x => x.Email == email);
                CustomersSessions sessionNew = new CustomersSessions();

                if (customer != null)
                {
                    Encryption encryption = new Encryption();

                    if (encryption.ValidatePassword(password, customer.Password))
                    {
                        SessionIDManager manager      = new SessionIDManager();
                        string           newSessionId = manager.CreateSessionID(HttpContext.Current);

                        string CurrentTime = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
                        string CurrentDate = DateTime.Now.Day + "/" + DateTime.Now.Month + "/" + DateTime.Now.Year;

                        sessionNew.CustomerId  = customer.Id;
                        sessionNew.SessionId   = newSessionId;
                        sessionNew.SessionDate = CurrentDate;
                        sessionNew.SessionTime = CurrentTime;
                        m_db.Sessions.Add(sessionNew);
                        m_db.SaveChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK, sessionNew));
                    }
                }
            }
            return(Request.CreateResponse(HttpStatusCode.Forbidden, "user name or password is invalid"));
        }
Пример #5
0
        public IHttpActionResult GetSuccessStories(CustomersSessions strSession)
        {
            SessionIDManager  manager = new SessionIDManager();
            CustomersSessions session = m_db.Sessions.SingleOrDefault(x => x.SessionId == strSession.SessionId);

            SessionController s = new SessionController();
            bool isExpired      = s.doesSessionExpired(strSession);

            if (isExpired)
            {
                manager.RemoveSessionID(HttpContext.Current);
                m_db.Sessions.Remove(session);
                m_db.SaveChanges();
                return(BadRequest("Your session expierd"));
            }
            else
            {
                string newSessionTime = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
                session.SessionTime = newSessionTime;
                return(Ok(m_db.SuccessStories.AsEnumerable()));
            }
        }