public ActionResult GetSessionCustomer()
 {
     SelectionOptionID customer = new SelectionOptionID(-1, "");
     var _session = sessionService.GetSession(this.HttpContext, true, false);
     if (_session.idCustomer != null)
     {
         var _customer = customers.GetAll().Where(c => c.id == _session.idCustomer).First();
         if (_customer != null)
         {
             customer.ID = _session.idCustomer.Value;
             customer.Label = _customer.fullName + " - Phone: " + _customer.mainPhone;
         };
     };
     return Json(customer);
 }
        public ActionResult SelectUser(string userEmail, string userPassword, string P1, string P2)
        {

            SelectionOptionID user = new SelectionOptionID(IDnotFound, "");
            person _person = new person();

            if (userEmail != null && userPassword != null)
            {
                var _session = sessionService.GetSession(this.HttpContext, false, false);
                bool personFound = false;
                bool userAuthor = false;

                string xP1 = _session.sessionGUID.Substring(0, 12);
                string xP2 = _session.sessionGUID.Substring(11, 12);

                if (P1 == xP1 && P2 == xP2)
                {
                    try //checks if person is in database
                    {
                        _person = persons.GetAll().Where(u => u.email == userEmail).
                            FirstOrDefault();
                        personFound = !(_person.Equals(default(person)));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("An error occurred: '{0}'", e);
                    }
                }
                // Person found in database
                if (personFound)
                {
                    userAuthor = sessionService.VerifyHash(_person.ID, userPassword);
                }
                // User is authorized
                if (userAuthor)
                {
                    user.ID = _person.ID;
                    user.Label = userEmail;
                    _session.idStaff = user.ID;
                }
                else
                {
                    user.ID = IDnotFound;
                    user.Label = string.Empty;
                    _session.idStaff = null;
                }
                sessions.Update(_session);
                sessions.Commit();
            }
            return Json(user);
        }
 public ActionResult SelectUser(string userEmail)
 {
     SelectionOptionID user = new SelectionOptionID(IDnotFound, "");
     if (userEmail != null)
     {
         var _session = sessionService.GetSession(this.HttpContext);
         var _users = users.GetAll().Where(q => q.person.email == userEmail);
         if (_users.Count() > 0)
         {
             user.ID = users.GetAll().Where(q => q.person.email == userEmail).First().ID;
             user.Label = userEmail;
             _session.idStaff = user.ID;
         }
         else
         {
             _session.idStaff = null;
         }
         sessions.Update(sessions.GetById(_session.ID));
         sessions.Commit();
     }
     return Json(user);
 }
 public ActionResult GetSessionEmail()
 {
     SelectionOptionID user = new SelectionOptionID(IDnotFound, "");
     var _session = sessionService.GetSession(this.HttpContext, false, false);
     if (_session.idStaff != null)
     {
         long userID = _session.idStaff.Value;
         var _user = users.GetByKey("id", userID);
         if (_user != null)
         {
             user.ID = _session.idStaff.Value;
             user.Label = _user.email;
         };
     };
     return Json(user);
 }
 public ActionResult GetSessionEmail()
 {
     SelectionOptionID user = new SelectionOptionID(IDnotFound, "");
     var _session = sessionService.GetSession(this.HttpContext);
     if (_session.idStaff != null)
     {
         staff _user = users.GetById(_session.idStaff);
         if (_user != null)
         {
             user.ID = _session.idStaff.Value;
             user.Label = _user.person.email;
         };
     };
     return Json(user);
 }