public async Task <IHttpActionResult> Post([FromBody] UserLogin req)
        {
            try
            {
                #region Validate
                string errorMessage = "UnknowError";
                string errorCode    = ErrorCodeEnum.UnknownError.ToString();
                if (!Validate(req, out errorCode, out errorMessage))
                {
                    return(Ok(new RequestErrorCode(false, errorCode, errorMessage)));
                }
                #endregion
                // check ton tai tai khoan
                var userLogin = MemoryInfo.GetListEmployeeByField(req.Email, Employee.EmployeeFields.Email).FirstOrDefault(x => x.Email == req.Email);
                if (userLogin == null)
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.Error_UserNotExist.ToString(), "Khong ton tai tai khoan")));
                }
                var passEncrypt = PasswordGenerator.EncodePassword(req.Password);
                if (userLogin.Password != passEncrypt)
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.Error_PasswordWrong.ToString(), "Sai password")));
                }

                var userInfo = MemoryInfo.GetEmployee(userLogin.Id);
                if (userInfo == null)
                {
                    return(Ok(new RequestErrorCode(false, ErrorCodeEnum.Error_UserinfoIsNull.ToString(), "Khong co thong tin Userinfo")));
                }

                #region Gen token va tra userInfo ve kem voi list quyen

                //var lstPermission = MemoryInfo.GetListPermission(userInfo.IdUserLogin);
                var token    = TokenManager.GenerateToken(userInfo, -1);
                var tokenRes = new TokenResponse(token, userInfo);
                //tokenRes.ListPermission.AddRange(lstPermission);
                #endregion
                var result = new RequestErrorCode(true);
                result.ListDataResult.Add(tokenRes);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                Logger.Write(ex.ToString());
            }

            Logger.Write("--------------------ErrorCodeEnum.Unknow---------------------------------");
            return(BadRequest("Unknow"));
        }
 public async Task <IHttpActionResult> Get()
 {
     try
     {
         #region token
         var header = Request.Headers;
         if (header.Authorization == null)
         {
             return(StatusCode(HttpStatusCode.Unauthorized));
         }
         var      token = header.Authorization.Parameter;
         Employee employee;
         if (string.IsNullOrWhiteSpace(token) || !TokenManager.ValidateToken(token, out employee))
         {
             return(StatusCode(HttpStatusCode.Unauthorized));
         }
         #endregion
         List <StoreRes> lstResult = new List <StoreRes>();
         var             lstData   = MemoryInfo.GetAllStore();
         foreach (var store in lstData)
         {
             if (store.IsDeleted != 1)
             {
                 var lstEmployees = MemoryInfo.GetListEmployeeByField(store.Id.ToString(), Employee.EmployeeFields.IdStore);
                 lstEmployees.ForEach(x => x.Password = null);
                 StoreRes itemRes = new StoreRes(store, lstEmployees);
                 lstResult.Add(itemRes);
             }
         }
         var res = new RequestErrorCode(true, null, null);
         res.ListDataResult.AddRange(lstResult);
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }
 public async Task <IHttpActionResult> Get(int id)
 {
     try
     {
         #region token
         var header = Request.Headers;
         if (header.Authorization == null)
         {
             return(StatusCode(HttpStatusCode.Unauthorized));
         }
         var      token = header.Authorization.Parameter;
         Employee employee;
         if (string.IsNullOrWhiteSpace(token) || !TokenManager.ValidateToken(token, out employee))
         {
             return(StatusCode(HttpStatusCode.Unauthorized));
         }
         #endregion
         var      data     = MemoryInfo.GetStore(id);
         StoreRes storeRes = null;
         if (data != null)
         {
             if (data.IsDeleted != 1)
             {
                 var lstEmployees = MemoryInfo.GetListEmployeeByField(data.Id.ToString(), Employee.EmployeeFields.IdStore);
                 lstEmployees.ForEach(x => x.Password = null);
                 storeRes = new StoreRes(data, lstEmployees);
             }
         }
         var res = new RequestErrorCode(true, null, null);
         res.DataResult = storeRes;
         return(Ok(res));
     }
     catch (Exception ex)
     {
         Logger.Write(ex.ToString());
     }
     return(BadRequest("Unknow"));
 }