public async Task <IHttpActionResult> PutCustomerAccountDTO(int id, CustomerAccountDTO customerAccountDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != customerAccountDTO.Id) { return(BadRequest()); } db.Entry(customerAccountDTO).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerAccountDTOExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
/// <summary> /// Allows you to populate the current customer account object using a CustomerAccount instance /// </summary> /// <param name="dto">An instance of the customer account from the REST API</param> public void FromDto(CustomerAccountDTO dto) { Bvin = dto.Bvin; Email = dto.Email; FirstName = dto.FirstName; LastName = dto.LastName; Password = dto.Password; TaxExempt = dto.TaxExempt; Notes = dto.Notes; PricingGroupId = dto.PricingGroupId; FailedLoginCount = dto.FailedLoginCount; LastUpdatedUtc = dto.LastUpdatedUtc; CreationDateUtc = dto.CreationDateUtc; LastLoginDateUtc = dto.LastLoginDateUtc; foreach (var a in dto.Addresses) { var addr = new Address(); addr.FromDto(a); Addresses.Add(addr); } ShippingAddress.FromDto(dto.ShippingAddress); BillingAddress.FromDto(dto.BillingAddress); }
public void FromDto(CustomerAccountDTO dto) { this.Bvin = dto.Bvin; this.Email = dto.Email; this.FirstName = dto.FirstName; this.LastName = dto.LastName; this.Password = dto.Password; this.Salt = dto.Salt; this.TaxExempt = dto.TaxExempt; this.Notes = dto.Notes; this.PricingGroupId = dto.PricingGroupId; this.FailedLoginCount = dto.FailedLoginCount; this.LastUpdatedUtc = dto.LastUpdatedUtc; this.CreationDateUtc = dto.CreationDateUtc; this.LastLoginDateUtc = dto.LastLoginDateUtc; foreach (AddressDTO a in dto.Addresses) { Contacts.Address addr = new Contacts.Address(); addr.FromDto(a); this.Addresses.Add(addr); } this.ShippingAddress.FromDto(dto.ShippingAddress); this.BillingAddress.FromDto(dto.BillingAddress); }
//DTO /// <summary> /// Allows you to convert the current customer account object to the DTO equivalent for use with the REST API /// </summary> /// <returns>A new instance of CustomerAccountDTO</returns> public CustomerAccountDTO ToDto() { var dto = new CustomerAccountDTO(); dto.Bvin = Bvin; dto.Email = Email; dto.FirstName = FirstName; dto.LastName = LastName; dto.Password = Password; dto.TaxExempt = TaxExempt; dto.Notes = Notes; dto.PricingGroupId = PricingGroupId; dto.FailedLoginCount = FailedLoginCount; dto.LastUpdatedUtc = LastUpdatedUtc; dto.CreationDateUtc = CreationDateUtc; dto.LastLoginDateUtc = LastLoginDateUtc; foreach (var a in Addresses) { dto.Addresses.Add(a.ToDto()); } dto.ShippingAddress = ShippingAddress.ToDto(); dto.BillingAddress = BillingAddress.ToDto(); return(dto); }
//DTO public CustomerAccountDTO ToDto() { CustomerAccountDTO dto = new CustomerAccountDTO(); dto.Bvin = this.Bvin; dto.Email = this.Email; dto.FirstName = this.FirstName; dto.LastName = this.LastName; dto.Password = this.Password; dto.Salt = this.Salt; dto.TaxExempt = this.TaxExempt; dto.Notes = this.Notes; dto.PricingGroupId = this.PricingGroupId; dto.FailedLoginCount = this.FailedLoginCount; dto.LastUpdatedUtc = this.LastUpdatedUtc; dto.CreationDateUtc = this.CreationDateUtc; dto.LastLoginDateUtc = this.LastLoginDateUtc; foreach (Contacts.Address a in this.Addresses) { dto.Addresses.Add(a.ToDto()); } dto.ShippingAddress = this.ShippingAddress.ToDto(); dto.BillingAddress = this.BillingAddress.ToDto(); return(dto); }
public async Task <IHttpActionResult> GetCustomerAccountDTO(int id) { CustomerAccountDTO customerAccountDTO = await db.CustomerAccountDTOes.FindAsync(id); if (customerAccountDTO == null) { return(NotFound()); } return(Ok(customerAccountDTO)); }
public async Task <IHttpActionResult> PostCustomerAccount(CustomerAccountDTO customerAccount) { //if (customerAccount==null) //{ // return BadRequest(ModelState); //} var response = await services.AddCustomerAccount(customerAccount); return(Ok(response)); }
public async Task <IHttpActionResult> PostCustomerAccountDTO(CustomerAccountDTO customerAccountDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.CustomerAccountDTOes.Add(customerAccountDTO); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = customerAccountDTO.Id }, customerAccountDTO)); }
public async Task <IHttpActionResult> DeleteCustomerAccountDTO(int id) { CustomerAccountDTO customerAccountDTO = await db.CustomerAccountDTOes.FindAsync(id); if (customerAccountDTO == null) { return(NotFound()); } db.CustomerAccountDTOes.Remove(customerAccountDTO); await db.SaveChangesAsync(); return(Ok(customerAccountDTO)); }
/// <summary> /// Create a Customer account /// </summary> /// <param name="customer"></param> /// <returns></returns> public async Task <string> AddCustomerAccount(CustomerAccountDTO customer) { if (customer == null) { return("Please provide a valid customer information."); } try { using (db = new PROVISIODBContext()) { var IsExistingCustomer = db.CustomerAccount.Any(c => c.ReferenceNumber == customer.ReferenceNumber || c.B_AccountNumber == customer.B_AccountNumber || c.MomoNumber == customer.MomoNumber); if (IsExistingCustomer) { TransactionErrorMessage = "There's an existing customer with the same Reference/Account number or Momo number"; return(null); } var new_customer = new CustomerAccount { Id = customer.Id, ReferenceNumber = customer.ReferenceNumber, B_AccountNumber = customer.B_AccountNumber, B_AccountName = customer.B_AccountName, B_Name = customer.B_Name, MomoNumber = customer.MomoNumber, MomoProvider = customer.MomoProvider, CustomerBalance = customer.CustomerBalance, TelephoneNumber = customer.TelephoneNumber, LastAccessed = customer.LastAccessed, Notes = customer.Notes }; db.CustomerAccount.Add(new_customer); var i = await db.SaveChangesAsync(); return(i > 0 ? "Account Created Successfully" : "Unale to Create Account, please contact API provider."); } } catch (Exception ex) { return(ex.Message); } }
//private void ProcessPage(int i) //{ // wl("Getting Users page " + (i + 1)); // int startRecord = i * 100; // var users = (from u in oldDatabase.bvc_User select u).OrderBy(y => y.Email).Skip(startRecord).Take(100).ToList(); // foreach (data.bvc_User u in users) // { // ImportSingleUser(u); // } //} private void ImportSingleUser(CustomerAccountDTO u) { if (u == null) { wl("Customer was null!"); return; } wl("Importing Customer: " + u.Email); Api bv6proxy = GetBV6Proxy(); var res = bv6proxy.CustomerAccountsCreate(u); if (res != null) { if (res.Errors.Count > 0) { DumpErrors(res.Errors); return; } wl("SUCCESS"); } }
/// <summary> /// Get all customers accounts /// </summary> /// <returns></returns> public IEnumerable <CustomerAccountDTO> GetAll_CustomersAccounts() { try { using (db = new PROVISIODBContext()) { var customersDTO = new List <CustomerAccountDTO>() ; var customers = db.CustomerAccount.ToList(); if (customers != null && customers.Count > 0) { foreach (var customer in customers) { var _customer = new CustomerAccountDTO { Id = customer.Id, ReferenceNumber = customer.ReferenceNumber, B_AccountNumber = customer.B_AccountNumber, B_AccountName = customer.B_AccountName, B_Name = customer.B_Name, MomoNumber = customer.MomoNumber, MomoProvider = customer.MomoProvider, CustomerBalance = customer.CustomerBalance, TelephoneNumber = customer.TelephoneNumber, LastAccessed = customer.LastAccessed, Notes = customer.Notes }; customersDTO.Add(_customer); } } return(customersDTO); } } catch (Exception ex) { TransactionErrorMessage = ex.Message; return(null); } }
public void CustomerAccount_TestCreateAndUpdateAndDelete() { //Create API Proxy var proxy = CreateApiProxy(); //Create Customer Account //User with tTest already exists var account = new CustomerAccountDTO { FirstName = "Tst", LastName = "Test", Email = "*****@*****.**", Password = "******", BillingAddress = new AddressDTO { City = "New York", CountryName = "United States", RegionName = "New York" } }; var createResponse = proxy.CustomerAccountsCreate(account); CheckErrors(createResponse); //Update Customer Account. account = createResponse.Content; account.TaxExempt = true; var updateResponse = proxy.CustomerAccountsUpdate(account); CheckErrors(updateResponse); Assert.IsTrue(updateResponse.Content.TaxExempt); //Delete Customer Account. var accountId = createResponse.Content.Bvin; var deleteResponse = proxy.CustomerAccountsDelete(accountId); CheckErrors(deleteResponse); Assert.IsTrue(deleteResponse.Content); }
// Create or Update public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata) { string data = string.Empty; string bvin = FirstParameter(parameters); ApiResponse <CustomerAccountDTO> response = new ApiResponse <CustomerAccountDTO>(); CustomerAccountDTO postedItem = null; try { postedItem = MerchantTribe.Web.Json.ObjectFromJson <CustomerAccountDTO>(postdata); } catch (Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return(MerchantTribe.Web.Json.ObjectToJson(response)); } CustomerAccount item = new CustomerAccount(); item.FromDto(postedItem); if (bvin == string.Empty) { CustomerAccount existing = MTApp.MembershipServices.Customers.FindByEmail(item.Email); if (existing == null || existing.Bvin == string.Empty) { string clearPassword = querystring["pwd"]; if (clearPassword.Trim().Length < 1) { clearPassword = MerchantTribe.Web.PasswordGenerator.GeneratePassword(10); } // Create bool result = MTApp.MembershipServices.CreateCustomer(item, clearPassword); bvin = item.Bvin; } else { bvin = existing.Bvin; } } else { MTApp.MembershipServices.UpdateCustomer(item); } CustomerAccount resultItem = MTApp.MembershipServices.Customers.Find(bvin); if (resultItem != null) { response.Content = resultItem.ToDto(); // Address Import foreach (AddressDTO a in postedItem.Addresses) { Address addr = new Address(); addr.FromDto(a); MTApp.MembershipServices.CheckIfNewAddressAndAddWithUpdate(resultItem, addr); } } data = MerchantTribe.Web.Json.ObjectToJson(response); return(data); }
/// <summary> /// Allows the REST API to create or update a category /// </summary> /// <param name="parameters"> /// Parameters passed in the URL of the REST API call. If there is a first parameter found in the /// URL, the method will assume it is the category ID (bvin) and that this is an update, otherwise it assumes to create /// a category. /// </param> /// <param name="querystring">Name/value pairs from the REST API call querystring. This is not used in this method.</param> /// <param name="postdata">Serialized (JSON) version of the CategoryDTO object</param> /// <returns>CategoryDTO - Serialized (JSON) version of the category</returns> public override string PostAction(string parameters, NameValueCollection querystring, string postdata) { var data = string.Empty; var bvin = FirstParameter(parameters); var response = new ApiResponse <CustomerAccountDTO>(); CustomerAccountDTO postedItem = null; try { postedItem = Json.ObjectFromJson <CustomerAccountDTO>(postdata); } catch (Exception ex) { response.Errors.Add(new ApiError("EXCEPTION", ex.Message)); return(Json.ObjectToJson(response)); } var item = new CustomerAccount(); item.FromDto(postedItem); if (bvin == string.Empty) { var existing = HccApp.MembershipServices.Customers.FindByEmail(item.Email).FirstOrDefault(); if (existing == null || existing.Bvin == string.Empty) { var clearPassword = item.Password; if (string.IsNullOrWhiteSpace(clearPassword)) { clearPassword = PasswordGenerator.GeneratePassword(10); } // Create var result = HccApp.MembershipServices.CreateCustomer(item, clearPassword); bvin = item.Bvin; } else { bvin = existing.Bvin; } } else { HccApp.MembershipServices.UpdateCustomer(item); } var resultItem = HccApp.MembershipServices.Customers.Find(bvin); if (resultItem != null) { response.Content = resultItem.ToDto(); // Address Import foreach (var a in postedItem.Addresses) { var addr = new Address(); addr.FromDto(a); HccApp.MembershipServices.CheckIfNewAddressAndAddWithUpdate(resultItem, addr); } } data = Json.ObjectToJson(response); return(data); }