Exemple #1
0
        public string UserLogin(UserTbl userLogin)
        {
            SessionResponse response = new SessionResponse();

            try
            {
                // UserTbl userLogin = JsonConvert.DeserializeObject<UserTbl>(userJson);
                var user = _userOperations.GetUser(userLogin.Username ?? userLogin.Email, userLogin.UserPassword);

                if (user == null)
                {
                    response.ResultFlag    = false;
                    response.ResultMessage = UserMessages.MissingUser;
                    response.ResultCode    = ResultCode.MissingUser.ToString();
                }
                else
                {
                    response.ResultFlag    = true;
                    response.ResultMessage = UserMessages.LoginSuccess;
                    response.ResultCode    = ResultCode.LoginSuccess.ToString();
                    response.UserDetails   = new UserModel()
                    {
                        Email    = user.Email,
                        Name     = user.Name,
                        Username = user.Username,
                        UserPreferredLanguage = user.UserPreferredLanguage,
                        UserTypeId            = user.UserTypeId,
                        UserId = user.UserID
                    };
                    if (response.UserDetails.UserTypeId == (int)UserTypesName.RestaurantAdministrator)
                    {
                        response.UserDetails.HasRestaurantConfigured = Convert.ToBoolean(_userOperations.CheckAdminHasRestaurant(response.UserDetails.Username, response.UserDetails.Email));
                    }
                    response.SessionKey = Guid.NewGuid().ToString();

                    HttpContext.Current.Session.Add("Session_ID", response.SessionKey);
                }
            }
            catch (Exception ex)
            {
                response.ResultFlag = false;
                response.ResultCode = ResultCode.OperationFailed.ToString();
                _logger.Log("UserLogin_Exception: ", ex.Message);
            }
            //return response;
            return(JsonConvert.SerializeObject(response));
        }