public IActionResult CreateUser([FromBody] CustomerResource customerResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } User result = new User(); if (customerResource.User.Role == "customer" || customerResource.User.Role == "") { var customer = _mapper.Map <CustomerResource, Customer>(customerResource); _context.Customers.Add(customer); _context.SaveChanges(); result = _context.Users.Find(customer.User.Id); } else if (customerResource.User.Role == "admin") { var admin = _mapper.Map <CustomerResource, Admin>(customerResource); _context.Admins.Add(admin); _context.SaveChanges(); result = _context.Users.Find(admin.User.Id); } var cr = _mapper.Map <User, UserResource>(result); return(Ok(cr)); }
public async Task <CustomerResource> Get(long Id) { CustomerResource CustomerResource = await DataContext.CustomerResource.AsNoTracking() .Where(x => x.Id == Id) .Where(x => x.DeletedAt == null) .Select(x => new CustomerResource() { CreatedAt = x.CreatedAt, UpdatedAt = x.UpdatedAt, Id = x.Id, Code = x.Code, Name = x.Name, StatusId = x.StatusId, Description = x.Description, Used = x.Used, RowId = x.RowId, Status = x.Status == null ? null : new Status { Id = x.Status.Id, Code = x.Status.Code, Name = x.Status.Name, }, }).FirstOrDefaultAsync(); if (CustomerResource == null) { return(null); } return(CustomerResource); }
public Client(Credentials credentials, IEnvironment env = null) { if (credentials == null) { throw new ArgumentNullException(nameof(credentials)); } environment = env ?? Environments.Production; requester = new Requester(credentials, environment, null, this.apiVersion); Account = new AccountResource(requester); Balance = new BalanceResource(requester); Charges = new ChargeResource(requester); Customers = new CustomerResource(requester); Disputes = new DisputeResource(requester); Events = new EventResource(requester); Forex = new ForexResource(requester); Links = new LinkResource(requester); Occurrences = new OccurrenceResource(requester); Sources = new PaymentSourceResource(requester); Receipts = new ReceiptResource(requester); Recipients = new RecipientResource(requester); Refunds = new RefundResource(requester); Schedules = new ScheduleResource(requester); Tokens = new TokenResource(requester); Transactions = new TransactionResource(requester); Transfers = new TransferResource(requester); }
public async Task <ActionResult <CustomerResource_CustomerResourceDTO> > Delete([FromBody] CustomerResource_CustomerResourceDTO CustomerResource_CustomerResourceDTO) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } if (!await HasPermission(CustomerResource_CustomerResourceDTO.Id)) { return(Forbid()); } CustomerResource CustomerResource = ConvertDTOToEntity(CustomerResource_CustomerResourceDTO); CustomerResource = await CustomerResourceService.Delete(CustomerResource); CustomerResource_CustomerResourceDTO = new CustomerResource_CustomerResourceDTO(CustomerResource); if (CustomerResource.IsValidated) { return(CustomerResource_CustomerResourceDTO); } else { return(BadRequest(CustomerResource_CustomerResourceDTO)); } }
public async Task <IActionResult> CreateCustomer([FromBody] CustomerResource customerResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var customer = mapper.Map <CustomerResource, Customer>(customerResource); if (customerRepository.CustomerExists(customer)) { return(BadRequest(Errors.AddErrorToModelState("login_failure", "Username already taken.", ModelState))); } customer.CustomerContact.CustomerTitle = staticDataRepository.GetTitle(customerResource.TitleId); customerRepository.Add(customer); await unitOfWork.CompleteAsync(); customer = await customerRepository.GetCustomer(customer.Id); var result = mapper.Map <Customer, CustomerResource>(customer); return(Ok(result)); }
public async Task <bool> Delete(CustomerResource CustomerResource) { if (await ValidateId(CustomerResource)) { } return(CustomerResource.IsValidated); }
public async Task <bool> Delete(CustomerResource CustomerResource) { await DataContext.CustomerResource.Where(x => x.Id == CustomerResource.Id).UpdateFromQueryAsync(x => new CustomerResourceDAO { DeletedAt = StaticParams.DateTimeNow, UpdatedAt = StaticParams.DateTimeNow }); return(true); }
public Step_1_Snapshot Take_Step_1_Snapshot(CustomerToAdd customerToAdd, CustomerResource actualCustomerReturned) { return(new Step_1_Snapshot { CustomerToAdd = customerToAdd, ActualCustomer = data.MobilesData.GetCustomerByGlobalId(actualCustomerReturned.GlobalId) }); }
public async Task <CustomerResource> AddAsync(CustomerResource resource) { Customer entity = ToEntity(resource); _db.Customers.Add(entity); await _db.SaveChangesAsync(); return(ToResource(entity)); }
public async Task <CustomerResource> ReplaceAsync(string id, CustomerResource resource) { Customer entity = await FindAsync(id); Mapper.Map(resource, entity); await _db.SaveChangesAsync(); return(ToResource(entity)); }
public Task ClientCan_ReceiveEmbeddedResourceCollection() { // Arrange the test resources that will be returned from the server // to test the client consumer code. var serverResource = new CustomerResource { CustomerId = Guid.NewGuid().ToString() }; // Embed to child resources. serverResource.Embed(new[] { new AddressResource { AddressId = Guid.NewGuid().ToString(), CustomerId = serverResource.CustomerId }, new AddressResource { AddressId = Guid.NewGuid().ToString(), CustomerId = serverResource.CustomerId } }, "addresses"); // Configure the mock service to return the resource. var mockSrv = new MockUnitTestService { Customers = new[] { serverResource } }; // Run the unit test and request the resource and assert the expected results. return(WebHostFixture.TestAsync <LinkGenerationTests>(async host => { var response = await host .ArrangeWithDefaults(mockSrv) .Act.OnRestClient(async client => { var request = ApiRequest.Get("api/customers/embedded/resource"); return await client.SendAsync <CustomerModel>(request); }); response.Assert.ApiResponse(apiResponse => { var resource = (CustomerModel)apiResponse.Content; // Validate that an embedded resource collection was returned. resource.Should().NotBeNull(); resource.Embedded.Should().NotBeNull(); resource.Embedded.Keys.Should().HaveCount(1); resource.Embedded.ContainsKey("addresses").Should().BeTrue(); // At this point, the embedded resource is the generic JSON.NET representation. // The next line of code will deserialize this generic representation in the C# client side class // matching the server-sided resource collection. var embeddedClientResource = resource.GetEmbeddedCollection <AddressModel>("addresses").ToArray(); embeddedClientResource.Should().NotBeNull(); embeddedClientResource.Should().HaveCount(2); }); })); }
public async Task <CustomerResource> Get(long Id) { CustomerResource CustomerResource = await UOW.CustomerResourceRepository.Get(Id); if (CustomerResource == null) { return(null); } return(CustomerResource); }
/// <summary> /// Parse customer from web to data model /// </summary> /// <param name="customer"></param> /// <returns></returns> public Customer ParseCustomer(CustomerResource customer) { return(new Customer() { //UserType = customer.UserType, Name = customer.Name, Email = customer.Email, Password = customer.Password }); }
public async Task ClientCan_ReceiveEmbeddedResourceCollection() { // Arrange the test resources that will be returned from the server // to test the client consumer code. var serverResource = new CustomerResource { CustomerId = Guid.NewGuid().ToString() }; var embeddedServerResource = new AddressResource { AddressId = Guid.NewGuid().ToString(), CustomerId = serverResource.CustomerId }; var embeddedServerResource2 = new AddressResource { AddressId = Guid.NewGuid().ToString(), CustomerId = serverResource.CustomerId }; serverResource.Embed(new[] { embeddedServerResource, embeddedServerResource2 }, "addresses"); var mockSrv = new MockUnitTestService { Customers = new CustomerResource[] { serverResource } }; // Create the test client and call route returning an embedded resource collection. var hostPlugin = new MockAppHostPlugin(); hostPlugin.AddPluginType <CustomerResourceMap>(); var client = RequestSettings.Create() .CreateTestClient(hostPlugin, mockSrv); var request = ApiRequest.Create("api/customers/embedded/resource", HttpMethod.Get); var response = await client.Send <CustomerModel>(request); // Validate that an embedded resource collection was returned. response.Content.Should().NotBeNull(); response.Content.Embedded.Should().NotBeNull(); response.Content.Embedded.Keys.Should().HaveCount(1); response.Content.Embedded.ContainsKey("addresses").Should().BeTrue(); // At this point, the embedded resource is the generic JSON.NET representation. // The next line of code will deserialize this generic representation in the C# client side class // matching the server-sided resource collection. var embeddedClientResource = response.Content.GetEmbeddedCollection <AddressModel>("addresses"); embeddedClientResource.Should().NotBeNull(); embeddedClientResource.Should().HaveCount(2); }
public async Task <IActionResult> Register(RegistrationCommand registration) { if (registration == null) { return(BadRequest("Customer and Address not specified.")); } Customer entity = await _messaging.SendAsync(registration); return(Ok(CustomerResource.FromEntity(entity))); }
public async Task <IActionResult> UpdateCustomer(int id, [FromBody] CustomerResource customer) { var Customer = await this.context.Customers.FindAsync(id); // Customer.Balance = newBalance; mapper.Map <CustomerResource, MeToYouCustomer>(customer, Customer); await this.context.SaveChangesAsync(); //var result = mapper.Map<MeToYouCustomer, CustomerResource>(Customer); return(Ok(Customer)); }
public async Task <IHttpActionResult> PostCustomer(CustomerResource resoure) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } CustomerResource result = await _customersService.AddAsync(resoure); return(CreatedAtRoute("DefaultApi", new { id = result.Id }, result)); }
public IActionResult GetCustomerByEmail(string email) { try { CustomerResource customer = _mapper.ParseCustomer(_customerService.GetCustomerByEmail(email)); return(Ok(customer)); } catch (Exception) { return(StatusCode(500)); } }
public async Task ClientSpecified_EnbeddedTypes_SentAsQueryString() { // Arrange the test resources that will be returned from the server // to test the client consumer code. var serverResource = new CustomerResource { CustomerId = Guid.NewGuid().ToString() }; var embeddedServerResource = new AddressResource { AddressId = Guid.NewGuid().ToString(), CustomerId = serverResource.CustomerId }; var embeddedServerResource2 = new AddressResource { AddressId = Guid.NewGuid().ToString(), CustomerId = serverResource.CustomerId }; var embeddedServerResource3 = new AddressResource { AddressId = Guid.NewGuid().ToString(), CustomerId = serverResource.CustomerId }; serverResource.Embed(new[] { embeddedServerResource, embeddedServerResource2 }, "addresses"); serverResource.Embed(embeddedServerResource3, "vacation-address"); var mockSrv = new MockUnitTestService { Customers = new CustomerResource[] { serverResource } }; // Create the test client and call route returning an embedded resource collection. var hostPlugin = new MockAppHostPlugin(); hostPlugin.AddPluginType <CustomerResourceMap>(); var client = RequestSettings.Create() .CreateTestClient(hostPlugin, mockSrv); var request = ApiRequest.Create("api/customers/embedded/resource", HttpMethod.Get).Embed("vacation-address"); var response = await client.Send <CustomerModel>(request); response.Request.RequestUri.Query.Should().Equals("?embed=vacation-address"); // If supported by the service then only one embedded resource should have been returned. response.Content.Embedded.Should().HaveCount(1); response.Content.Embedded.ContainsKey("vacation-address").Should().BeTrue(); }
public async Task <IHttpActionResult> PutCustomer(string id, CustomerResource resource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } resource.Id = id; await _customersService.ReplaceAsync(id, resource); return(StatusCode(HttpStatusCode.NoContent)); }
public IActionResult AddCustomer(CustomerResource newCustomer) { try { _customerService.AddCustomer(_mapper.ParseCustomer(newCustomer)); _customerService.SaveChanges(); return(CreatedAtAction("AddCustomer", newCustomer)); } catch (Exception) { return(BadRequest()); } }
public async Task <IHttpActionResult> GetCustomer(string id) { try { CustomerResource resource = await _customersService.SingleAsync(id); return(Ok(resource)); } catch (KeyNotFoundException) { return(NotFound()); } }
public CustomerResource_CustomerResourceDTO(CustomerResource CustomerResource) { this.Id = CustomerResource.Id; this.Code = CustomerResource.Code; this.Name = CustomerResource.Name; this.StatusId = CustomerResource.StatusId; this.Description = CustomerResource.Description; this.Used = CustomerResource.Used; this.RowId = CustomerResource.RowId; this.Status = CustomerResource.Status == null ? null : new CustomerResource_StatusDTO(CustomerResource.Status); this.CreatedAt = CustomerResource.CreatedAt; this.UpdatedAt = CustomerResource.UpdatedAt; this.Errors = CustomerResource.Errors; }
public CallLog_CustomerResourceDTO(CustomerResource CustomerResource) { this.Id = CustomerResource.Id; this.Name = CustomerResource.Name; this.Code = CustomerResource.Code; this.StatusId = CustomerResource.StatusId; this.Description = CustomerResource.Description; this.Errors = CustomerResource.Errors; }
public IActionResult Insert([FromBody] CustomerResource customerResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var customer = _mapper.Map <CustomerResource, Customer>(customerResource); customer.CreateTimeStamp = DateTime.UtcNow; _unitOfWork.Customers.Add(customer); _unitOfWork.Complete(); return(Created(new Uri(Request.GetDisplayUrl() + "/" + customer.Id), Mapper.Map <Customer, CustomerResource>(customer))); }
public static async Task <string> CreateCustomersAsync(AuthenticationProvider authenticationProvider, Client customer) { try { // Converter objeto order para invoice CustomerResource resource = Mappers.ToCustomer(customer); // Inserir invoice do IE return(await CustomerController.InsertCustomerToIEAsync(authenticationProvider, resource).ConfigureAwait(false)); } catch (Exception exception) { throw new ExecutionEngineException(exception.Message); } }
public AddressResource(CustomerResource customer) { var address = customer.addresses.First(); region = address.region.region; regionId = address.region.region_id; regionCode = address.region.region_code; countryId = address.country_id; street = address.street; telephone = address.telephone; postcode = address.postcode; city = address.city; firstname = address.firstname; lastname = address.lastname; email = customer.email; }
public async Task <IActionResult> Lookup(Guid id, [FromQuery] bool includeSuggestions) { var query = new QueryCustomer(id) { IncludedSuggestions = includeSuggestions }; CustomerInfo info = await _messaging.DispatchAsync(query); if (info == null) { return(NotFound("Contact not registered.")); } return(Ok(CustomerResource.FromEntity(info))); }
public async Task <ActionResult> Post([FromBody] CustomerResource customerResource) { try { var customer = Mapper.Map <CustomerResource, Customer>(customerResource); CustomerRepository.Add(customer); var customerRes = Mapper.Map <Customer, CustomerResource>(customer); return(new CreatedResult("http://localhost:42097/api/Customers/" + customer.Id, customerRes)); } catch (Exception e) { return(new BadRequestResult()); } }
public Client(Credentials credentials) { if (credentials == null) throw new ArgumentNullException("credentials"); requester = new Requester(credentials); Account = new AccountResource(requester); Balance = new BalanceResource(requester); Cards = new CardResourceShim(requester); Charges = new ChargeResource(requester); Customers = new CustomerResource(requester); Disputes = new DisputeResource(requester); Events = new EventResource(requester); Recipients = new RecipientResource(requester); Refunds = new RefundResourceShim(requester); Tokens = new TokenResource(requester); Transactions = new TransactionResource(requester); Transfers = new TransferResource(requester); }
public async Task <IActionResult> Update([FromRoute] Guid id, [FromBody] CustomerResource customerResource) { if (customerResource == null) { customerResource = new CustomerResource(); } var customer = _mapper.Map <CustomerResource, Customer>(customerResource); var result = await _customersService.UpdateAsync(id, customer); if (!result.Success) { return(BadRequest(result)); } return(Ok(result)); }