public ApiException(
     HttpStatusCode responseStatusCode,
     ErrorResponseBase errorResponse,
     string message
     ) : base(message)
 {
     ErrorResponse      = errorResponse;
     ResponseStatusCode = responseStatusCode;
 }
Example #2
0
 public NotFoundException(
     HttpStatusCode responseStatusCode,
     ErrorResponseBase errorResponse,
     string message,
     Exception innerException
     ) : base(
         responseStatusCode,
         errorResponse,
         message,
         innerException
         ) => ErrorResponse = errorResponse;
Example #3
0
 public NotFoundException(
     HttpStatusCode responseStatusCode,
     ErrorResponseBase errorResponse,
     string message
     ) : base(
         responseStatusCode,
         errorResponse,
         message
         )
 {
 }
Example #4
0
        public ResponseBase <StaffResponse> Add(RequestBase request)
        {
            var response = new ResponseBase <StaffResponse>();

            var data = JsonConvert.DeserializeObject <StaffRequestDto>(request.data.ToString());
            /// check exist staff
            var staffHelperBo = new StaffHelperBo();
            var isExist       = staffHelperBo.IsExist(data.Username);

            // if exist staff => return error message

            if (isExist)
            {
                response.message = "Staff already existed";
                response.success = false;
                return(response);
            }
            else
            {
                //else if not exist => add new staff => return result
                //data.Password = Common.Md5Hash(data.Password);
                data.Password = BCrypt.Net.BCrypt.HashPassword(data.Password);
                try
                {
                    var res = staffHelperBo.Add(data);
                    if (res)
                    {
                        response.message = "Insert new staff successfully.";
                        response.success = true;
                    }
                    else
                    {
                        response.message = "Can't insert new staff.";
                        response.success = false;
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.WriteError(this.ToString(), "Stack Trace: " + ex.StackTrace);
                    LogUtil.WriteError(this.ToString(), "Message: " + ex.Message.ToString());
                    ErrorResponseBase errorResponse = new ErrorResponseBase();
                    errorResponse.errCode = ex.GetHashCode().ToString();;
                    errorResponse.message = ex.Message.ToString();
                    response.success      = false;
                    response.message      = "error";
                    response.error        = errorResponse;
                }
            }
            return(response);
        }
 public ApiException(HttpStatusCode responseStatusCode, ErrorResponseBase errorResponse) : base(errorResponse?.Error?.Message)
 {
     ErrorResponse      = errorResponse;
     ResponseStatusCode = responseStatusCode;
 }
Example #6
0
        public async Task <ResponseBase <CustomerResponse> > Add()
        {
            var response = new ResponseBase <CustomerResponse>();

            if (!Request.Content.IsMimeMultipartContent())
            {
                response.success = false;
                response.message = "Unsupported Media Type";
                return(response);
            }
            var request     = "";
            var listFileNew = new List <FileAndMimeType>();

            var filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

            foreach (var item in filesReadToProvider.Contents)
            {
                if (item.Headers.ContentDisposition.Name == "\"jsonKey\"")
                {
                    request = await item.ReadAsStringAsync();
                }
                else
                {
                    var obj = new FileAndMimeType();

                    var fileBytes = await item.ReadAsByteArrayAsync();

                    obj.file     = fileBytes;
                    obj.fileName = item.Headers.ContentDisposition.FileName;
                    listFileNew.Add(obj);
                }
            }


            // staff : who logged in into system, will upload customer information for registering for one customer
            var dataRequest  = JsonConvert.DeserializeObject <RequestBase>(request);
            var dataRequest1 = dataRequest.data;
            var data         = JsonConvert.DeserializeObject <CustomerDto>(dataRequest1.ToString());

            var helper  = new HelperBo();
            var isExist = helper.IsExistWhere("customers", " Idnumber = " + data.IdNumber);

            if (data.IdNumber == null)
            {
                response.message = "Customer Id can not be emty";
                response.success = false;
                return(response);
            }

            if (data.CIF == null)
            {
                response.message = "Customer Persnonal Identify can not be emty";
                response.success = false;
                return(response);
            }
            // if exist Customer => Still Save file to local, return success and message "Customer already existed";
            if (isExist.message == "1")
            {
                data.UrlPath = FileSaveHelper.SaveFileToLocal(listFileNew, data);

                if (data.UrlPath == null)
                {
                    // don't have file
                    response.message = "File not found.";
                    response.success = false;
                    return(response);
                }
                else
                {
                    response.message = "Customer already existed, only Insert the file";
                    response.success = true;
                    return(response);
                }
            }
            else
            {
                //else if not exist => get the file from request, upload to folder in server add new Customer => return result
                var folderCustomer = data.Name.ToString().Replace(" ", String.Empty).RemoveCharacterUnicode().Trim() + data.IdNumber.ToString().Trim();

                var folderStaff = data.StaffId.ToString().Trim();

                try
                {
                    data.UrlPath = FileSaveHelper.SaveFileToLocal(listFileNew, data);

                    if (data.UrlPath == null)
                    {
                        // don't have file
                        response.message = "File not found.";
                        response.success = false;
                        return(response);
                    }

                    //var res = CustomerHelperBo.Add(data);
                    var res = helper.Add("customers", data);
                    if (res.success)
                    {
                        response.message = "Insert new customer successfully.";
                        response.success = true;
                    }
                    else
                    {
                        response.message = "Can't insert new customer.";
                        response.success = false;
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.WriteError(this.ToString(), "Stack Trace: " + ex.StackTrace);
                    LogUtil.WriteError(this.ToString(), "Message: " + ex.Message.ToString());
                    ErrorResponseBase errorResponse = new ErrorResponseBase();
                    errorResponse.errCode = ex.StackTrace.ToString();
                    errorResponse.message = ex.Message.ToString();
                    response.success      = false;
                    response.message      = "error";
                    response.error        = errorResponse;
                }
            }
            return(response);
        }
Example #7
0
        public ResponseBase <StaffResponse> Login(RequestBase request)
        {
            var response = new ResponseBase <StaffResponse>();

            var data = JsonConvert.DeserializeObject <StaffRequestDto>(request.data.ToString());

            /// validate data request
            ///
            if (data == null || data.Username == null || data.Password == null)
            {
                response.message = "User or Password is Empty";
                response.success = false;
                return(response);
            }

            //data.Password = Common.Md5Hash(data.Password);
            //data.Password = BCrypt.Net.BCrypt.HashPassword(data.Password);
            var staffHelperBo = new StaffHelperBo();

            try
            {
                var login = staffHelperBo.GetUserByName(data);

                if (login.Username != null)
                {
                    var isTrue = BCrypt.Net.BCrypt.Verify(data.Password, login.Password);

                    if (isTrue)
                    {
                        response.message = "Login Success";
                        response.success = true;
                        var dataReponse = new StaffResponse();
                        dataReponse.data = new System.Collections.Generic.List <StaffDataResponse>();
                        dataReponse.data.Add(new StaffDataResponse(login.ID, login.Name, login.Username, login.Password, login.CreatedDate));
                        response.data = dataReponse;
                        return(response);
                    }
                    else
                    {
                        response.message = "Wrong User or Password";
                        response.success = false;
                        return(response);
                    }
                }
                else
                {
                    response.message = "User or Password does not exist";
                    response.success = false;
                    return(response);
                }
            }
            catch (Exception ex)
            {
                LogUtil.WriteError(this.ToString(), "Stack Trace: " + ex.StackTrace);
                LogUtil.WriteError(this.ToString(), "Message: " + ex.Message.ToString());
                ErrorResponseBase errorResponse = new ErrorResponseBase();
                errorResponse.errCode = ex.GetHashCode().ToString();;
                errorResponse.message = ex.Message.ToString();
                response.success      = false;
                response.message      = "error";
                response.error        = errorResponse;
            }
            //
            return(response);
        }