public override Task OnExceptionAsync(ExceptionContext context) { logManager.AddLog(context.Exception); HttpStatusCode status; string code, message; if (context.Exception is NotImplementedException) { status = HttpStatusCode.NotImplemented; code = "MethodNotImplemented"; message = Resources.errMethodNotImplemented; } else { status = HttpStatusCode.InternalServerError; code = "SystemError"; message = settings.Value.IsProduction ? Resources.errGeneral : logManager.GetExceptionDetails(context.Exception); } context.HttpContext.Response.StatusCode = (int)status; context.Result = new JsonResult(new HttpErrorMessage(code, message)); return(base.OnExceptionAsync(context)); }
public string CreateTokenAuthentication(int userId) { try { string CacheName = ConfigManagerConst.TokenCacheName + userId; var TokenKey = Guid.NewGuid().ToString(); long ExpireDate = DateTime.Now.AddMinutes(ConfigManager.GetData(ConfigManagerConst.TokenExpireTime).ToDouble()).ToLong(); var Entity = new TokenAuthenticationEntity { UserId = userId, ExpireDate = ExpireDate, TokenKey = TokenKey }; if (IsExsistCachedDataByName <TokenAuthenticationEntity>(CacheName)) { RemoveCachedDataSingleByName <TokenAuthenticationEntity>(CacheName); } AddSingleCachedData(CacheName, Entity, DateTime.Now.AddMinutes(ConfigManager.GetData(ConfigManagerConst.TokenCacheTime).ToDouble())); return(TokenKey); } catch (KnownException ex) { throw ex; } catch (Exception ex) { _logger.AddLog(LogTypeEnum.Error, "AuthenticationManager.CreateTokenAuthentication", userId, ex.Message, ex); throw new KnownException(ErrorTypeEnum.GeneralExeption, ex.Message, ex); } }
public override void Intercept(IInvocation invocation) { var start = DateTime.Now; invocation.Proceed(); var end = DateTime.Now; _logManager.AddLog(invocation, end - start); }
internal (HttpStatusCode status, string code) ProcessException(Exception exception) { logManager.AddLog(LogCategory.GeneralError, exception); HttpStatusCode status; string code; if (exception is NotImplementedException) { status = HttpStatusCode.NotImplemented; code = "MethodNotImplemented"; } else { status = HttpStatusCode.InternalServerError; code = "SystemError"; } return(status, code); }
public CustomerDto CreateOrUpdateCustomer(CustomerDto dto, int RequestUserId, string TokenKey) { try { CheckAuthentication(RequestUserId, TokenKey); #region Empty Control if (dto.UserName.IsNullOrEmpty()) { throw new RequestWarningException(ErrorTypeEnum.WarningException, ExceptionCodeHelper.CannotEmptyField, ExceptionMessageHelper.CannotEmptyField("User Name")); } if (dto.Password.IsNullOrEmpty()) { throw new RequestWarningException(ErrorTypeEnum.WarningException, ExceptionCodeHelper.CannotEmptyField, ExceptionMessageHelper.CannotEmptyField("Password")); } if (dto.FullName.IsNullOrEmpty()) { throw new RequestWarningException(ErrorTypeEnum.WarningException, ExceptionCodeHelper.CannotEmptyField, ExceptionMessageHelper.CannotEmptyField("Full Name")); } #endregion var data = GetAllCachedData <CustomerDto>().ToList(); #region Field Control if (data != null) { if (data.Any(q => q.UserName == dto.UserName)) { throw new RequestWarningException(ErrorTypeEnum.WarningException, ExceptionCodeHelper.IsInUse, ExceptionMessageHelper.IsInUse("UserName")); } } #endregion var entity = dto.ConvertTo <CustomerEntity>(); var Pass = PasswordHelper.GeneratePassword(6); entity.Password = (dto.Id > 0) ? PasswordHelper.EncryptData(dto.Password) : PasswordHelper.EncryptData(Pass); var conn = Db.CreateConnection(true); if (dto.Id > 0) { entity.UpdateUser = RequestUserId; entity.UpdateDate = DateTimeHelper.Now; conn.Update(entity, Db._DbTransaction); data.RemoveAt(data.FindIndex(q => q.Id == entity.Id)); } else { int Id = conn.Insert(entity, Db._DbTransaction).ToInt(); entity = conn.Get <CustomerEntity>(Id); } var result = entity.ConvertTo <CustomerDto>(); data.Add(result); FillCacheData(data); return(result); } catch (KnownException ex) { throw ex; } catch (Exception ex) { Logger.AddLog(LogTypeEnum.Error, "CustomerManager.CreateOrUpdateCustomer", RequestUserId, ex.Message, dto.ToJson(), ex); throw new KnownException(ErrorTypeEnum.UnexpectedExeption, ex.Message, ex); } }
public ProductTypeDto CreateOrUpdateProductType(ProductTypeDto dto, int RequestUserId, string TokenKey) { try { CheckAuthentication(RequestUserId, TokenKey); #region Empty Control if (dto.Name.IsNullOrEmpty()) { throw new RequestWarningException(ErrorTypeEnum.WarningException, ExceptionCodeHelper.CannotEmptyField, ExceptionMessageHelper.CannotEmptyField("Name")); } #endregion var data = GetAllCachedData <ProductTypeEntity>().ToList(); #region Field Control if (data != null) { if (data.Any(q => q.Name == dto.Name)) { throw new RequestWarningException(ErrorTypeEnum.WarningException, ExceptionCodeHelper.IsInUse, ExceptionMessageHelper.IsInUse("Name")); } } #endregion var entity = dto.ConvertTo <ProductTypeEntity>(); var conn = Db.CreateConnection(true); if (dto.Id > 0) { entity.UpdateUser = RequestUserId; entity.UpdateDate = DateTimeHelper.Now; conn.Update(entity, Db._DbTransaction); data.RemoveAt(data.FindIndex(q => q.Id == entity.Id)); } else { int Id = conn.Insert(entity, Db._DbTransaction).ToInt(); entity = conn.Get <ProductTypeEntity>(Id); } data.Add(entity); FillCacheData(data); return(entity.ConvertTo <ProductTypeDto>()); } catch (KnownException ex) { throw ex; } catch (Exception ex) { Logger.AddLog(LogTypeEnum.Error, "ProductManager.CreateOrUpdateProductType", RequestUserId, ex.Message, dto.ToJson(), ex); throw new KnownException(ErrorTypeEnum.UnexpectedExeption, ex.Message, ex); } }