private void CheckInVariants(BaseAPIResponse response) { StringBuilder errorMessageSB = new StringBuilder(1024); if (this.logger == null) { errorMessageSB.Append("NULL Logger object."); } if (this.core == null) { errorMessageSB.Append("NULL EvolentHealthAPICore object."); } if (errorMessageSB.Length > 0) { response.NullObjects(errorMessageSB.ToString()); if (this.logger != null) { this.logger.LogErrorMessage(this.GetType(), errorMessageSB.ToString()); } } else { response.Success(); } }
public IActionResult GetAllCustomers() { var response = new BaseAPIResponse <List <CustomerAPIModel> >(); try { var customers = customerService.GetAllCustomers(); var responseData = customers.Select(x => new CustomerAPIModel { FirstName = x.FirstName, LastName = x.LastName, CustomerType = x.CustomerType, MobileNumber = x.MobileNumber, Id = x.Id.ToString() }).ToList(); response.ResponseCode = ResponseConstants.SuccessCode; response.ResponseMessage = ResponseConstants.SuccessMessage; response.Result = responseData; return(Ok(response)); } catch (Exception ex) { log.LogError("GetAllCustomers Error: {ex}", ex); response.ResponseCode = ResponseConstants.ErrorCode; response.ResponseMessage = ResponseConstants.ErrorMessage; return(Ok(response)); } }
public IActionResult GetCustomerByName([FromQuery] string firstName, [FromQuery] string lastName) { var response = new BaseAPIResponse <CustomerAPIModel>(); try { var customer = customerService.GetCustomerByName(firstName, lastName); if (customer != null) { var responseData = new CustomerAPIModel(); responseData.FirstName = customer.FirstName; responseData.LastName = customer.LastName;; responseData.CustomerType = customer.CustomerType; responseData.MobileNumber = customer.MobileNumber; responseData.Id = customer.Id.ToString(); response.Result = responseData; } else { response.Result = null; } response.ResponseCode = ResponseConstants.SuccessCode; response.ResponseMessage = ResponseConstants.SuccessMessage; return(Ok(response)); } catch (Exception ex) { log.LogError("GetCustomerByName Error: {ex}", ex); response.ResponseCode = ResponseConstants.ErrorCode; response.ResponseMessage = ResponseConstants.ErrorMessage; return(Ok(response)); } }
public IActionResult GetAllDiscounts() { var response = new BaseAPIResponse <List <DiscountAPIModel> >(); try { var discounts = discountService.GetAllDiscounts(); var responseData = discounts.Select(x => new DiscountAPIModel { Name = x.Name, Percentage = x.Percentage }).ToList(); response.ResponseCode = ResponseConstants.SuccessCode; response.ResponseMessage = ResponseConstants.SuccessMessage; response.Result = responseData; return(Ok(response)); } catch (Exception ex) { log.LogError("GetAllDiscounts Error: {ex}", ex); response.ResponseCode = ResponseConstants.ErrorCode; response.ResponseMessage = ResponseConstants.ErrorMessage; return(Ok(response)); } }
public IActionResult CreateDiscount([FromBody] DiscountAPIModel discountAPIModel) { var response = new BaseAPIResponse <bool>(); try { if (ModelState.IsValid) { var discount = new Discount { Name = discountAPIModel.Name, Percentage = discountAPIModel.Percentage, DateCreated = DateTime.Now }; var result = discountService.CreateDiscount(discount); response.ResponseCode = ResponseConstants.SuccessCode; response.ResponseMessage = ResponseConstants.SuccessMessage; response.Result = result; return(Ok(response)); } else { return(BadRequest(ModelState)); } } catch (Exception ex) { log.LogError("CreateDiscount Error: {ex}", ex); response.ResponseCode = ResponseConstants.ErrorCode; response.ResponseMessage = ResponseConstants.ErrorMessage; return(Ok(response)); } }
public IActionResult GetDiscountDetails([FromRoute] string Id) { var response = new BaseAPIResponse <DiscountAPIModel>(); try { var discount = discountService.GetDiscountDetails(Id); if (discount != null) { var responseData = new DiscountAPIModel(); responseData.Name = discount.Name; responseData.Percentage = discount.Percentage; response.Result = responseData; } else { response.Result = null; } response.ResponseCode = ResponseConstants.SuccessCode; response.ResponseMessage = ResponseConstants.SuccessMessage; return(Ok(response)); } catch (Exception ex) { log.LogError("GetDiscountDetails Error: {ex}", ex); response.ResponseCode = ResponseConstants.ErrorCode; response.ResponseMessage = ResponseConstants.ErrorMessage; return(Ok(response)); } }
public IActionResult GetInvoiceAmount([FromBody] InvoiceRequestModel invoiceRequestModel) { var response = new BaseAPIResponse <InvoiceResponseModel>(); try { if (ModelState.IsValid) { var result = invoiceService.ComputeInvoiceAmount(invoiceRequestModel.Items, invoiceRequestModel.CustomerId); response.ResponseCode = ResponseConstants.SuccessCode; response.ResponseMessage = ResponseConstants.SuccessMessage; response.Result = new InvoiceResponseModel { InvoiceAmount = result }; return(Ok(response)); } else { return(BadRequest(ModelState)); } } catch (Exception ex) { log.LogError("GetInvoiceAmount Error: {ex}", ex); response.ResponseCode = ResponseConstants.ErrorCode; response.ResponseMessage = ResponseConstants.ErrorMessage; return(Ok(response)); } }
public BaseAPIResponse CheckLoginStatus(int userId, string ip) { var result = new BaseAPIResponse(); try { UsersHelper help = new UsersHelper(); List<ABiAdminUsers> list = help.getUsersByID(userId); if (list != null && list.Count > 0) { ABiAdminUsers obj = list[0]; if (!obj.Status) { result.ResponseCode = (int)APIResponseCode.User_Locked; result.ResponseMessage = "用户被锁或用户不存在"; } else if (obj.LoginStatus != "1" || obj.LastLogin < DateTime.Now.AddMinutes(-15)) { result.ResponseCode = (int)APIResponseCode.Login_Expired; result.ResponseMessage = "登录过期,请重新登录"; } else { obj.LastLogin = DateTime.Now; obj.LoginStatus = "1"; obj.IPAddress = ip;//Request.UserHostAddress; help.updateUsersLastLogin(obj); result.ResponseCode = (int)APIResponseCode.Success; result.ResponseMessage = "Success"; } } } catch (Exception ex) { result.ResponseCode = (int)APIResponseCode.System_Error; result.ResponseMessage = ex.Message; } return result; }
public IActionResult CreateCustomer([FromBody] CreateCustomerModel createCustomerModel) { var response = new BaseAPIResponse <bool>(); try { if (ModelState.IsValid) { var customer = new Customer { FirstName = createCustomerModel.FirstName, LastName = createCustomerModel.LastName, DateCreated = DateTime.Now, MobileNumber = createCustomerModel.MobileNumber, CustomerType = createCustomerModel.CustomerType }; var result = customerService.CreateCustomer(customer); response.ResponseCode = ResponseConstants.SuccessCode; response.ResponseMessage = ResponseConstants.SuccessMessage; response.Result = result; return(Ok(response)); } else { return(BadRequest(ModelState)); } } catch (Exception ex) { log.LogError("CreateCustomer Error: {ex}", ex); response.ResponseCode = ResponseConstants.ErrorCode; response.ResponseMessage = ResponseConstants.ErrorMessage; return(Ok(response)); } }