public IActionResult Update(CustomerListDTO oCustomerVm) { var oRespuesta = new BaseResponse(); try { using (var db = new BDTiendaContext()) { var oCustomer = db.Cliente.Find(oCustomerVm.IdCliente); oCustomer.Nombre = oCustomerVm.Nombre; oCustomer.ApellidoPaterno = oCustomerVm.ApellidoPaterno; oCustomer.ApellidoMaterno = oCustomerVm.ApellidoMaterno; oCustomer.Dni = oCustomerVm.Dni; db.Entry(oCustomer).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); oRespuesta.Success = true; } } catch (Exception ex) { oRespuesta.Message = ex.Message; } return(Ok(oRespuesta)); }
public IActionResult Add(CustomerListDTO oCustomerVm) { var oRespuesta = new BaseResponse(); try { using (var db = new BDTiendaContext()) { var oCustomer = new Cliente(); oCustomer.Nombre = oCustomerVm.Nombre; oCustomer.ApellidoPaterno = oCustomerVm.ApellidoPaterno; oCustomer.ApellidoMaterno = oCustomerVm.ApellidoMaterno; oCustomer.Dni = oCustomerVm.Dni; db.Cliente.Add(oCustomer); db.SaveChanges(); oRespuesta.Success = true; } } catch (Exception ex) { oRespuesta.Message = ex.Message; } return(Ok(oRespuesta)); }
public void CustomerEnumerableToCustomerListDTOListAdapt() { //Arrange var country = new Country("Spain", "es-ES"); country.GenerateNewIdentity(); var address = new Address("Monforte", "27400", "AddressLine1", "AddressLine2"); var customer = CustomerFactory.CreateCustomer("Jhon", "El rojo", "617404929", "Spirtis", country, address); var picture = new Picture { RawPhoto = new byte[0] { } }; customer.ChangeTheCurrentCredit(1000M); customer.ChangePicture(picture); customer.SetTheCountryForThisCustomer(country); IEnumerable <Customer> customers = new List <Customer>() { customer }; //Act ITypeAdapter adapter = TypeAdapterFactory.CreateAdapter(); var dtos = adapter.Adapt <IEnumerable <Customer>, List <CustomerListDTO> >(customers); //Assert Assert.IsNotNull(dtos); Assert.IsTrue(dtos.Any()); Assert.IsTrue(dtos.Count == 1); CustomerListDTO dto = dtos[0]; Assert.AreEqual(customer.Id, dto.Id); Assert.AreEqual(customer.FirstName, dto.FirstName); Assert.AreEqual(customer.LastName, dto.LastName); Assert.AreEqual(customer.Company, dto.Company); Assert.AreEqual(customer.Telephone, dto.Telephone); Assert.AreEqual(customer.CreditLimit, dto.CreditLimit); Assert.AreEqual(customer.Address.City, dto.AddressCity); Assert.AreEqual(customer.Address.ZipCode, dto.AddressZipCode); Assert.AreEqual(customer.Address.AddressLine1, dto.AddressAddressLine1); Assert.AreEqual(customer.Address.AddressLine2, dto.AddressAddressLine2); }
/// <summary> /// Initializes a new instance of the <see cref="VMCustomerListView"/> class. /// </summary> public VMCustomerListView() { deleteCommand = new DelegateCommand<object>(DeleteExecute); editCommand = new DelegateCommand<object>(EditExecute); viewCommand = new DelegateCommand<object>(ViewExecute); addCommand = new DelegateCommand<object>(AddExecute); searchCommand = new DelegateCommand<object>(SearchExecute); _customers = new ObservableCollection<CustomerListDTO>(); this._currentCustomer = new CustomerListDTO(); if (!DesignTimeHelper.IsDesignTime) { GetCustomers(); } }
public async Task Create_Saves_New_Customer() { var jsonContextMock = new MockJsonRepositoryContext(); var customerRepo = new CustomerJSONRepository(jsonContextMock); var customer = new Customer("Sit"); await customerRepo.Create(customer); CustomerListDTO updatedObject = JsonConvert.DeserializeObject <CustomerListDTO>(jsonContextMock.mockJson); var updatedCustomer = updatedObject.Customers.FirstOrDefault(c => c.Id == customer.Id && c.Name == customer.Name); Assert.NotNull(updatedCustomer); }
/// <summary> /// Initializes a new instance of the <see cref="VMCustomerListView"/> class. /// </summary> public VMCustomerListView() { deleteCommand = new DelegateCommand <object>(DeleteExecute); editCommand = new DelegateCommand <object>(EditExecute); viewCommand = new DelegateCommand <object>(ViewExecute); addCommand = new DelegateCommand <object>(AddExecute); searchCommand = new DelegateCommand <object>(SearchExecute); _customers = new ObservableCollection <CustomerListDTO>(); this._currentCustomer = new CustomerListDTO(); if (!DesignTimeHelper.IsDesignTime) { GetCustomers(); } }
public CustomerListDTO CustomerListDTOMapper(Customer customer) { CustomerListDTO customerDTO = new CustomerListDTO(); customerDTO.ID = customer.ID; customerDTO.value = customer.Name; customerDTO.Address1 = customer.Address1; customerDTO.Address2 = customer.Address2; customerDTO.City = customer.City; customerDTO.Zip = customer.Zip; customerDTO.State = customer.State; customerDTO.ShippingAddress1 = customer.ShippingAddress1; customerDTO.ShippingAddress2 = customer.ShippingAddress2; customerDTO.ShippingCity = customer.ShippingCity; customerDTO.ShippingZip = customer.ShippingZip; customerDTO.ShippingState = customer.ShippingState; return(customerDTO); }
public async Task <LogicResult <IEnumerable <CustomerListDTO> > > GetAllCustomerByOutlet(int idoutlet) { var unitOfWork = _repositoryHelper.GetUnitOfWork(); var appointmentdtRepo = _repositoryHelper.GetRepository <IAppoitmentDetailRepository>(unitOfWork); var outletRepo = _repositoryHelper.GetRepository <IOutletRepository>(unitOfWork); //var appointmentDetailRepo = _repositoryHelper.GetRepository<IAppoitmentDetailRepository>(unitOfWork); var currentOutlet = await outletRepo.GetByIdAsync(idoutlet); if (currentOutlet == null) { return(new LogicResult <IEnumerable <CustomerListDTO> >() { IsSuccess = false, message = Validation.OuletNotInSystem }); } var app = await appointmentdtRepo.GetAllCustomerByOutlet(idoutlet); var customerlistdto = new List <CustomerListDTO>(); foreach (var item in app) { var customer = new CustomerListDTO() { name = item.Appointment1.Customer1.Name, phonenumber = item.Appointment1.Customer1.Phone, avt = item.Appointment1.Customer1.Avatar, email = item.Appointment1.Customer1.Email, nric = item.Appointment1.Customer1.NRIC.ToString() }; customerlistdto.Add(customer); } ; return(new LogicResult <IEnumerable <CustomerListDTO> >() { IsSuccess = true, Result = customerlistdto }); }
public void TestCustomerViewModel() { CustomerViewModel customerViewModel = new CustomerViewModel(); customerViewModel.Service = serviceFacade; CustomerListDTO customer = new CustomerListDTO() { Id = 1 }; IList <CustomerListDTO> customers = new List <CustomerListDTO>() { customer }; Expect.Once.On(serviceFacade).Method("GetAllCustomers").Will(Return.Value(customers)); customerViewModel.LoadCommand.Command.Execute(null); Assert.AreEqual <int>(1, customerViewModel.Items.Count); Assert.AreEqual(customer, customerViewModel.SelectedItem); Assert.AreEqual(Strings.CustomerViewModel_DisplayName, customerViewModel.DisplayName); }
public async Task Update_Saves_New_Customer() { string newName = "Jim"; var customer = new Customer(newName); //We will change Lorem's name customer.Id = 1; var jsonContextMock = new MockJsonRepositoryContext(); var customerRepo = new CustomerJSONRepository(jsonContextMock); await customerRepo.Update(customer); CustomerListDTO updatedObject = JsonConvert.DeserializeObject <CustomerListDTO>(jsonContextMock.mockJson); var updatedCustomer = updatedObject.Customers.FirstOrDefault(c => c.Id == customer.Id); Assert.NotNull(updatedCustomer); }
public void TestCustomersToDtos() { Customer customer = new Customer() { CustomerId = 1, Name = "FakeUserName", FirstName = "FakeFirstName", Version = 0, Title = "Herr" }; Order order1 = new Order() { OrderId = 1, OrderStatus = OrderStatus.Draft }; Order order2 = new Order() { OrderId = 2, OrderStatus = OrderStatus.Ordered }; customer.Orders = new List <Order>() { order1, order2 }.AsQueryable(); Assert.AreEqual(true, customer.IsValid); IQueryable <Customer> customers = new List <Customer>() { customer }.AsQueryable(); IList <CustomerListDTO> customerDtos = CustomerAdapter.CustomersToDtos(customers); Assert.AreEqual <int>(1, customerDtos.Count()); CustomerListDTO dto = customerDtos.First(); Assert.AreEqual <int>(customer.CustomerId, dto.Id); Assert.AreEqual <string>(customer.Name, dto.Name); Assert.AreEqual <string>(customer.FirstName, dto.FirstName); Assert.AreEqual <int>(2, dto.NumberOfTotalOrders); Assert.AreEqual <int>(1, dto.NumberOfOpenOrders); Assert.AreEqual(true, dto.IsValid); }