public HttpResponseMessage GetCustomers(HttpRequestMessage request, [FromBody] CustomerInformation customerInformation) { TransactionalInformation transaction = new TransactionalInformation(); string customerCode = customerInformation.CustomerCode; string companyName = customerInformation.CompanyName; int currentPageNumber = customerInformation.CurrentPageNumber; int pageSize = customerInformation.PageSize; string sortExpression = customerInformation.SortExpression; string sortDirection = customerInformation.SortDirection; int totalRows = 0; CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService); List <Customer> customers = customerBusinessService.GetCustomers(customerCode, companyName, currentPageNumber, pageSize, sortDirection, sortExpression, out totalRows, out transaction); if (transaction.ReturnStatus == false) { var badResponse = Request.CreateResponse <TransactionalInformation>(HttpStatusCode.BadRequest, transaction); return(badResponse); } customerInformation = new CustomerInformation(); customerInformation.ReturnStatus = transaction.ReturnStatus; customerInformation.TotalRows = totalRows; customerInformation.TotalPages = Utilities.CalculateTotalPages(totalRows, pageSize); customerInformation.ReturnMessage.Add("page " + currentPageNumber + " of " + customerInformation.TotalPages + " returned at " + DateTime.Now.ToString()); customerInformation.Customers = customers; var response = Request.CreateResponse <CustomerInformation>(HttpStatusCode.OK, customerInformation); return(response); }
public IActionResult Login(HttpRequestMessage request, [FromBody] CustomerModel customerModel) { TransactionalBase transaction = new TransactionalBase(); string emailAddress = customerModel.EmailAddress; string password = customerModel.Password; CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService); Customer customer = customerBusinessService.Login(emailAddress, password, out transaction); if (transaction.ReturnStatus == false) { return(new ObjectResult(transaction)); } string tokenString = TokenManager.CreateToken(customer.Id); customerModel.Id = customer.Id; customerModel.EmailAddress = customer.EmailAddress; customerModel.FirstName = customer.FirstName; customerModel.LastName = customer.LastName; customerModel.IsAuthenticated = true; customerModel.Token = tokenString; customerModel.ReturnStatus = true; customerModel.ReturnMessage = transaction.ReturnMessage; customerModel.Token = tokenString; return(new ObjectResult(customerModel)); }
public HttpResponseMessage GetCustomers(HttpRequestMessage request, [FromBody] CustomerViewModel customerViewModel) { TransactionalInformation transaction; int currentPageNumber = customerViewModel.CurrentPageNumber; int pageSize = customerViewModel.PageSize; string sortExpression = customerViewModel.SortExpression; string sortDirection = customerViewModel.SortDirection; CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService); List <Customer> customers = customerBusinessService.GetCustomers(currentPageNumber, pageSize, sortExpression, sortDirection, out transaction); if (transaction.ReturnStatus == false) { customerViewModel.ReturnStatus = false; customerViewModel.ReturnMessage = transaction.ReturnMessage; customerViewModel.ValidationErrors = transaction.ValidationErrors; var responseError = Request.CreateResponse <CustomerViewModel>(HttpStatusCode.BadRequest, customerViewModel); return(responseError); } customerViewModel.TotalPages = transaction.TotalPages; customerViewModel.TotalRows = transaction.TotalRows; customerViewModel.Customers = customers; customerViewModel.ReturnStatus = true; customerViewModel.ReturnMessage = transaction.ReturnMessage; var response = Request.CreateResponse <CustomerViewModel>(HttpStatusCode.OK, customerViewModel); return(response); }
public MainWindow() { cService = new CustomerService(); businessService = new CustomerBusinessService(cService); InitializeComponent(); LoadData(); }
public IActionResult GetCustomer(HttpRequestMessage request, [FromQuery] string Id) { CustomerModel customer = new CustomerModel(); CustomerBusinessService userBusinessService = new CustomerBusinessService(_customerDataService); userBusinessService.GetCustomer(Guid.Parse(Id), out customer); return(new ObjectResult(customer)); }
public HttpResponseMessage UpdateCustomer(HttpRequestMessage request, [FromBody] CustomerDTO dto) { TransactionalInformation transaction = new TransactionalInformation(); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // REVERT //if (request.Headers.Authorization == null) //{ // transaction.ReturnMessage.Add("Your session is invalid."); // transaction.ReturnStatus = false; // var badResponse = Request.CreateResponse<TransactionalInformation>(HttpStatusCode.Unauthorized, transaction); // return badResponse; //} //string tokenString = request.Headers.Authorization.ToString(); //ClaimsPrincipal principal = TokenManager.ValidateToken(tokenString); //if (principal == null) //{ // transaction.ReturnMessage.Add("Your session is invalid."); // transaction.ReturnStatus = false; // var badResponse = Request.CreateResponse<TransactionalInformation>(HttpStatusCode.Unauthorized, transaction); // return badResponse; //} var rd = new Random(); if (dto.CustomerCode == null) { dto.CustomerCode = rd.Next().ToString(); } CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService); customerBusinessService.UpdateCustomer(dto, out transaction); if (transaction.ReturnStatus == false) { var badResponse = Request.CreateResponse <TransactionalInformation>(HttpStatusCode.BadRequest, transaction); return(badResponse); } dto.ReturnStatus = true; dto.ReturnMessage = transaction.ReturnMessage; var response = Request.CreateResponse <CustomerDTO>(HttpStatusCode.OK, dto); return(response); }
public IActionResult UpdateProfile(HttpRequestMessage request, [FromBody] CustomerModel customerInformation) { TransactionalBase transaction = new TransactionalBase(); if (request.Headers.Authorization == null) { transaction.ReturnMessage.Add("Your are not authorized"); transaction.ReturnStatus = false; return(new ObjectResult(transaction)); } string tokenString = request.Headers.Authorization.ToString(); ClaimsPrincipal principal = TokenManager.ValidateToken(tokenString); if (principal == null) { transaction.ReturnMessage.Add("Your are not authorized"); transaction.ReturnStatus = false; return(new ObjectResult(transaction)); } Guid userID = TokenManager.GetUserID(Request.Headers["Authorization"].ToString()); if (userID == Guid.Empty) { transaction.ReturnMessage.Add("Your are not authorized"); transaction.ReturnStatus = false; return(new ObjectResult(transaction)); } customerInformation.Id = userID; CustomerBusinessService userBusinessService = new CustomerBusinessService(_customerDataService); userBusinessService.UpdateProfile(customerInformation, out transaction); if (transaction.ReturnStatus == false) { return(new ObjectResult(transaction)); } customerInformation.ReturnStatus = transaction.ReturnStatus; customerInformation.ReturnMessage = transaction.ReturnMessage; customerInformation.Token = tokenString; return(new ObjectResult(customerInformation)); }
public HttpResponseMessage InitializeData(HttpRequestMessage request) { TransactionalInformation transaction; CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService); customerBusinessService.InitializeData(out transaction); if (transaction.ReturnStatus == false) { var responseError = Request.CreateResponse <TransactionalInformation>(HttpStatusCode.BadRequest, transaction); return(responseError); } var response = Request.CreateResponse <TransactionalInformation>(HttpStatusCode.OK, transaction); return(response); }
public static T Create <T>(BusinessType businessType) where T : IBusinessService { var businessService = default(IBusinessService); switch (businessType) { case BusinessType.Customers: businessService = new CustomerBusinessService(); break; case BusinessType.Orders: businessService = new OrderBusinessService(); break; default: throw new ArgumentException("Invalid business service type"); } return((T)businessService); }
public IActionResult RegisterCustomer(HttpRequestMessage request, [FromBody] CustomerModel customerInformation) { TransactionalBase transaction = new TransactionalBase(); Guid customerID = new Guid(); customerInformation.IpAddress = request.GetClientIpAddress(); CustomerBusinessService userBusinessService = new CustomerBusinessService(_customerDataService); userBusinessService.RegisterCustomer(customerInformation, out customerID, out transaction); if (transaction.ReturnStatus == false) { return(new ObjectResult(transaction)); } customerInformation.ReturnStatus = true; customerInformation.ReturnMessage = transaction.ReturnMessage; customerInformation.Token = TokenManager.CreateToken(customerID); customerInformation.IsAuthenticated = true; return(new ObjectResult(customerInformation)); }
public HttpResponseMessage ImportCustomers(HttpRequestMessage request, [FromBody] CustomerInformation customerInformation) { TransactionalInformation transaction = new TransactionalInformation(); CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService); customerBusinessService.ImportCustomers(out transaction); if (transaction.ReturnStatus == false) { var badResponse = Request.CreateResponse <TransactionalInformation>(HttpStatusCode.BadRequest, transaction); return(badResponse); } customerInformation = new CustomerInformation(); customerInformation.ReturnMessage = transaction.ReturnMessage; customerInformation.ReturnStatus = transaction.ReturnStatus; var response = Request.CreateResponse <CustomerInformation>(HttpStatusCode.OK, customerInformation); return(response); }
public HttpResponseMessage GetCustomer(HttpRequestMessage request, [FromBody] CustomerDTO dto) { TransactionalInformation transaction = new TransactionalInformation(); int customerID = dto.CustomerID; CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService); dto = customerBusinessService.GetCustomer(customerID, out transaction); if (transaction.ReturnStatus == false) { var badResponse = Request.CreateResponse <TransactionalInformation>(HttpStatusCode.BadRequest, transaction); return(badResponse); } dto.ReturnStatus = transaction.ReturnStatus; var response = Request.CreateResponse <CustomerDTO>(HttpStatusCode.OK, dto); return(response); }
public HttpResponseMessage UpdateCustomer(HttpRequestMessage request, [FromBody] CustomerInformation customerInformation) { TransactionalInformation transaction = new TransactionalInformation(); if (request.Headers.Authorization == null) { transaction.ReturnMessage.Add("Your session is invalid."); transaction.ReturnStatus = false; var badResponse = Request.CreateResponse <TransactionalInformation>(HttpStatusCode.Unauthorized, transaction); return(badResponse); } string tokenString = request.Headers.Authorization.ToString(); ClaimsPrincipal principal = TokenManager.ValidateToken(tokenString); if (principal == null) { transaction.ReturnMessage.Add("Your session is invalid."); transaction.ReturnStatus = false; var badResponse = Request.CreateResponse <TransactionalInformation>(HttpStatusCode.Unauthorized, transaction); return(badResponse); } CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService); customerBusinessService.UpdateCustomer(customerInformation, out transaction); if (transaction.ReturnStatus == false) { var badResponse = Request.CreateResponse <TransactionalInformation>(HttpStatusCode.BadRequest, transaction); return(badResponse); } customerInformation.ReturnStatus = true; customerInformation.ReturnMessage = transaction.ReturnMessage; var response = Request.CreateResponse <CustomerInformation>(HttpStatusCode.OK, customerInformation); return(response); }
public HttpResponseMessage UpdateCustomer(HttpRequestMessage request, [FromBody] CustomerViewModel customerViewModel) { TransactionalInformation transaction; Customer customer = new Customer(); customer.CustomerID = customerViewModel.CustomerID; customer.CompanyName = customerViewModel.CompanyName; customer.ContactName = customerViewModel.ContactName; customer.ContactTitle = customerViewModel.ContactTitle; customer.CustomerCode = customerViewModel.CustomerCode; customer.Address = customerViewModel.Address; customer.City = customerViewModel.City; customer.Region = customerViewModel.Region; customer.PostalCode = customerViewModel.PostalCode; customer.Country = customerViewModel.Country; customer.PhoneNumber = customerViewModel.PhoneNumber; customer.MobileNumber = customerViewModel.MobileNumber; CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService); customerBusinessService.UpdateCustomer(customer, out transaction); if (transaction.ReturnStatus == false) { customerViewModel.ReturnStatus = false; customerViewModel.ReturnMessage = transaction.ReturnMessage; customerViewModel.ValidationErrors = transaction.ValidationErrors; var responseError = Request.CreateResponse <CustomerViewModel>(HttpStatusCode.BadRequest, customerViewModel); return(responseError); } customerViewModel.ReturnStatus = true; customerViewModel.ReturnMessage = transaction.ReturnMessage; var response = Request.CreateResponse <CustomerViewModel>(HttpStatusCode.OK, customerViewModel); return(response); }
public void TestMethod1() { // need to moq the function that connect to db and fetches the data List <Customer> fakeCustomers = new List <Customer>(); fakeCustomers.Add(new Customer { Name = "A" }); fakeCustomers.Add(new Customer { Name = "A" }); fakeCustomers.Add(new Customer { Name = "B" }); var mock = new Mock <ICustomerService>(); mock.Setup(x => x.GetCustomers()).Returns(fakeCustomers); CustomerBusinessService serviceTobeTested = new CustomerBusinessService(mock.Object); Assert.IsTrue(serviceTobeTested.GetCountOfNames("A") == 2); }