public void TestInit() { _customerRepository = Ioc.Create<ICustomerRepository>(); _customerRepository.Clear(); _customerA = Customer.GetCustomerA(); _customerB = Customer.GetCustomerB(); _customerRepository.Add( _customerA ); _customerRepository.Add( _customerB ); }
public void TestInit() { //添加测试数据 _customerRepository = Ioc.Create<ICustomerRepository>(); _customerRepository.Clear(); _customerRepository.Add( Customer.GetCustomerA() ); _customerRepository.Add( Customer.GetCustomerB() ); //创建查询对象 _query = new Query<Customer, int>(); }
public void TestInit() { //设置基础数据 _customerRepository = Ioc.Create<ICustomerRepository>(); _customerRepository.Clear(); _customerRepository.Add( Customer.GetCustomerA() ); _customerRepository.Add( Customer.GetCustomerB() ); _customerRepository.Add( Customer.GetCustomerC() ); //设置查询 _queryable = _customerRepository.Find(); }
public void TestInit() { //添加测试数据 _customerRepository = Ioc.Create<ICustomerRepository>(); _customerRepository.Clear(); for( int i = 0; i < 6; i++ ) { _customerRepository.Add( Customer.GetCustomerA() ); _customerRepository.Add( Customer.GetCustomerB() ); _customerRepository.Add( Customer.GetCustomerC() ); } //创建查询对象 _query = new Query<Customer, int>(); _query.PageSize = 3; _query.OrderBy( t => t.Name ); }
private static void AddCustomerTest(ICustomerRepository customerRepository) { Customer customer = new Customer { FirstName = "Marcin", LastName = "Sulecki", }; customerRepository.Add(customer); }
public async Task <IActionResult> PostCustomer(Customer customer) { _repo.Add(customer); if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to save Notes")); }
public IActionResult Create([FromBody] Customer c) { if (c == null) { return(BadRequest()); // 400 Bad request } repo.Add(c); return(CreatedAtRoute("GetCustomer", new { id = c.CustomerID.ToLower() }, c)); // 201 Created }
/// <summary> /// This function manage data from service to repository pattern. /// There is also called creation of Billing info. /// </summary> /// <param name="item">Inserted object</param> /// <returns>Pre-mapped object</returns> public Customer Create(CustomerDTO item) { var billingInfo = _billingInfoFactory.Create(item.BillingInfo); item.BillingInfo = _mapper.Map <BillingInfoDTO>(billingInfo); _repository.Add(item); _repository.Save(); return(_mapper.Map <Customer>(item)); }
public HttpResponseMessage PostCustomer(Customer customer) { customer = repository.Add(customer); var response = Request.CreateResponse <Customer>(HttpStatusCode.Created, customer); string uri = Url.Link("DefaultApi", new { id = customer.Id }); response.Headers.Location = new Uri(uri); return(response); }
public async Task <IActionResult> PostCustomer([FromBody] Customer customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _customerRepository.Add(customer); return(CreatedAtAction("getCustomer", new { id = customer.CustomerId })); }
public async Task Create(CustomerModel customer) { await customerRepository.Add(new Domain.Customer { Id = Guid.NewGuid(), Age = customer.Age, Firstname = customer.Firstname, Lastname = customer.Lastname }); }
public void Execute(CreateCustomerCommand command) { var email = new EmailAddress(command.Email); var name = new Name(command.FirstName, command.SecondName); var customer = new Customer(command.CustomerIdentityToken, email, name); _customerRepository.Add(customer); _uow.Commit(); }
public void SeedData() { var isDataExists = _groupRepository.GetAll().Result; if (isDataExists.Count() > 0) { Assert.Pass(); return; } var silverGroup = new Group("Silver", 10); var platinumGroup = new Group("Platinum", 50); var goldGroup = new Group("Gold", 30); var customerOne = new Customer("Saiful", silverGroup); var customerTwo = new Customer("Riaz", platinumGroup); var customerThree = new Customer("Faisal", goldGroup); var babyToy = new Product("Baby Toy", 100); var babySoap = new Product("Baby Soap", 80); var babyFood = new Product("Baby Food", 150); var babyHygine = new Product("Baby Hygine", 50); var babyPampas = new Product("Baby Pampas", 120); _groupRepository.Add(silverGroup); _groupRepository.Add(goldGroup); _groupRepository.Add(platinumGroup); _customerRepository.Add(customerOne); _customerRepository.Add(customerTwo); _customerRepository.Add(customerThree); _productRepository.Add(babyToy); _productRepository.Add(babySoap); _productRepository.Add(babyFood); _productRepository.Add(babyHygine); _productRepository.Add(babyPampas); bool result = _unitOfWork.Commit().Result; Assert.IsTrue(result); }
public long Add(Customer customer) { try { return(__repository.Add(customer)); } catch (Exception) { throw; } }
public async Task <IActionResult> Post([FromBody] CustomerModel customer) { var saved = await _repository.Add(customer); if (!saved) { return(BadRequest(saved)); } return(Ok(saved)); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } await customerRepository.Add(Customer); return(RedirectToPage("./Index")); }
public IActionResult Post([FromBody] Customer customer) { customerRepository.Add(customer); //string url = $"http://localhost:5000/api/customers/{customer.Id}"; //return Created(url, customer); // return CreatedAtRoute(new { Id = customer.Id }, customer); return(CreatedAtRoute(nameof(GetById), new { Id = customer.Id }, customer)); }
public void SQLCustomerRepository_Add_Delete_From_Multiple_Customer_Entries() { ICustomerRepository sut = GetInMemoryCustomerRepository(); List <Customer> customer = CustomerInMemoryDb(); Customer savedCustomer1 = sut.Add(customer[0]); Customer savedCustomer2 = sut.Add(customer[1]); Assert.Equal(2, sut.GetAllCustomers(1).Count()); Assert.Equal("Jack", savedCustomer1.FirstName); Assert.Equal("Joe", savedCustomer2.FirstName); sut.Delete(customer[0].Id); Assert.Single(sut.GetAllCustomers(1)); Assert.Equal("Joe", sut.GetCustomer(2).FirstName); }
[ProducesResponseType(StatusCodes.Status500InternalServerError)] // if something unexpectedly went wrong with the database or http request/response public async Task <ActionResult <Furs2Feathers.Domain.Models.Customer> > PostCustomer(Furs2Feathers.Domain.Models.Customer customer) { customerRepo.Add(customer); await customerRepo.SaveChangesAsync(); int highest_id = customerRepo.HighestID(); customer.CustomerId = highest_id; return(CreatedAtAction("GetCustomer", new { id = customer.CustomerId }, customer)); }
public IActionResult Create([FromBody] Customer c) { if (c == null) { return(BadRequest()); // 400 Bad Request } repo.Add(c); // return a 201 Created with a route to get the object // the route will be the value of the Location header in the response. return(CreatedAtRoute("GetCustomer", new { id = c.CustomerID.ToUpper() }, c)); }
/// <summary> /// Returns a new Model.Customer with CustomerSince=Now and adds it to the repository /// </summary> /// <returns></returns> private Customer CreateNewCustomer() { var customer = new Customer(); _repository.Add(customer); //Set defaults for new Customer: customer.CustomerSince = DateTime.Now; return(customer); }
public IActionResult Create([FromBody] Customer customer) { if (customer == null) { return(BadRequest()); } _customerRepository.Add(customer); return(CreatedAtRoute("GetCustomer", new { id = customer.CustomerId }, customer)); }
public bool signUp(Customer customer) { if (!customerRepository.customers.Any(c => c.username == customer.username)) { return(customerRepository.Add(customer)); } else { return(false); } }
public Customer Add(Customer entity) { if (entity == null) { throw new ArgumentNullException("entity"); } var ret = _repository.Add(CustomerMap.MapBack(entity)); return(CustomerMap.Map(ret)); }
public void CreateCustomer(Customer customer) { bool CustomerExists = customerRepository.IsUserExists(customer.Username); if (CustomerExists) { throw new InvalidOperationException("Customer already exists"); } customerRepository.Add(customer); }
public void Add(CustomerModel obj) { if (obj == null) { return; } var customer = Mapper.Map <CustomerModel, Customer>(obj); _customerRepository.Add(customer); _customerRepository.Save(); }
public IActionResult Post([FromBody] Customer customer) { if (customer == null) { return(BadRequest()); } var createNewCustomer = _customerRepository.Add(customer); return(CreatedAtRoute("GetCustomer", new { id = createNewCustomer.Id }, createNewCustomer)); }
public IActionResult Create([FromBody] CustomerItem item) { if (item == null) { return(BadRequest()); } _CustomerRepository.Add(item); return(CreatedAtRoute("GetCustomer", new { id = item.Key }, item)); }
public async Task <IActionResult> Create([Bind("CustomerId,Login,Password,FirstName,LastName,PhoneNumber,DefaultLocation")] Customer customer) { if (ModelState.IsValid) { await _repository.Add(customer); _repository.Save(); return(RedirectToAction("Index", "Login")); } return(View(customer)); }
public void Post([FromBody] SaveCustomerViewModel sCustomer) { var customer = new CustomerViewModel { FirstName = sCustomer.FirstName, LastName = sCustomer.LastName, MemberSince = sCustomer.MemberSince, Wallet = sCustomer.Wallet }; _repository.Add(customer.ToModel()); }
/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.Application.MainModule.CustomersManagement.ICustomerManagementService"/> /// </summary> /// <param name="customer"><see cref="Microsoft.Samples.NLayerApp.Application.MainModule.CustomersManagement.ICustomerManagementService"/></param> public void AddCustomer(Customer customer) { //Begin unit of work ( if Transaction is required init here a new TransactionScope element IUnitOfWork unitOfWork = _customerRepository.UnitOfWork as IUnitOfWork; _customerRepository.Add(customer); //Complete changes in this unit of work unitOfWork.Commit(); }
public Customer InsertGuestCusomter(Guid?customerGuid = null) { var customer = new Customer { CustomerGuid = customerGuid ?? Guid.NewGuid(), Active = true, CreatedOnUtc = DateTime.UtcNow, LastActivityDateUtc = DateTime.UtcNow }; return(_customerRepository.Add(customer)); }
public void Add_a_new_Customer(CustomerCommand command) { var customer = new Customer(command.Name, command.Email); if (customer.IsValid()) { _customerRepository.Add(customer); return; } throw new Exception("Invalid Customer."); }
public async Task <IActionResult> CreateAsync([FromBody] CreateCustomer request, CancellationToken cancellationToken) { var address = _mapper.Map <Domain.Address>(request.Address); var customer = new Customer(request.Name, address); _customerRepository.Add(customer); await _customerRepository.UnitOfWork.SaveChangesAsync(cancellationToken); var vm = _mapper.Map <ViewCustomer>(customer); return(CreatedAtAction(nameof(GetAsync), new { id = vm.Id }, vm)); }
private void UpdateContactLabels(ICustomerRepository repository) { //delete old values var originalValues = CurrentCustomer.Labels.ToList(); foreach (var labelItem in originalValues) { if (CustomerDetailViewModel.ContactLabels.All(l => l.LabelId != labelItem.LabelId)) { if (CurrentCustomer == null) break; CurrentCustomer.Labels.Remove(labelItem); repository.Attach(labelItem); repository.Remove(labelItem); } } //add new values foreach (var labelItem in CustomerDetailViewModel.ContactLabels) { if (_originalContact.Labels.All(l => l.LabelId != labelItem.LabelId)) { if (CurrentCustomer == null) break; labelItem.MemberId = CurrentCustomer.MemberId; repository.Add(labelItem); CurrentCustomer.Labels.Add(labelItem); } } repository.UnitOfWork.Commit(); }
private void UpdateCaseLabels(ICustomerRepository repository) { //delete old values var originalLabels = InnerItem.Labels.ToList(); foreach (var labelItem in originalLabels) { if (CaseDetailViewModel.CaseLabelList.All(l => l.LabelId != labelItem.LabelId)) { InnerItem.Labels.Remove(labelItem); repository.Attach(labelItem); repository.Remove(labelItem); } } //add new values foreach (var labelItem in CaseDetailViewModel.CaseLabelList) { if (_originalItem.Labels.All(l => l.LabelId != labelItem.LabelId)) { labelItem.CaseId = InnerItem.CaseId; repository.Add(labelItem); InnerItem.Labels.Add(labelItem); } } repository.UnitOfWork.Commit(); }
/// <summary> /// add notes to InnerItem from CaseCommunicationViewModel /// </summary> private void GetNotesToCaseFromCaseCommunications(ICustomerRepository repository) { var adaptor = new CommunicationAdaptor(); if (CaseCommunications != null && CaseCommunications.Items != null) { var result = new List<Note>(); result = result.Union(CaseCommunications.Items .Where(n => n.Type == CommunicationItemType.Note) .Where( n => n.State != CommunicationItemState.Deleted) .Select( n => adaptor.NoteCommunicationViewModel2Note( n as CommunicationItemNoteViewModel))).ToList(); foreach (var note in result) { var noteForUpdate = CaseNotes.SingleOrDefault(caseNote => caseNote.NoteId == note.NoteId); if (noteForUpdate == null) { note.CaseId = InnerItem.CaseId; CaseNotes.Add(note); repository.Add(note); } } //if messsage was writed in textbox, but Enter was not pressed //then create new noteItem and save it; if (!string.IsNullOrEmpty(CaseCommunications.NewBody)) { var activeCommand = CaseCommunications.ToolBarCommmands.SingleOrDefault(c => c.IsActive); if ((CommunicationItemType)activeCommand.CommandParametr == CommunicationItemType.Note) { var note = new Note { AuthorName = _authorName, Body = CaseCommunications.NewBody, Title = InnerItem.Title, Created = (DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Local)).ToUniversalTime(), CaseId = InnerItem.CaseId }; note.LastModified = note.Created; CaseNotes.Add(note); repository.Add(note); } OnUIThread(() => { if (activeCommand != null) { activeCommand.Command.Execute(CaseCommunications.NewBody); } }); } } }
/// <summary> /// Add communication item to CurrentCase /// </summary> /// <returns></returns> private void GetCommunicationItemsFromCaseCommunications(ICustomerRepository repository) { var adaptor = new CommunicationAdaptor(); if (CaseCommunications != null && CaseCommunications.Items != null) { var result = new List<CommunicationItem>(); result = result.Union(CaseCommunications.Items .Where(item => item.Type == CommunicationItemType.PublicReply) .Where(item => item.State != CommunicationItemState.Deleted) .Select( item => adaptor.PublicReplyViewModel2PublicReplyItem( item as CommunicationItemPublicReplyViewModel))).ToList(); foreach (var item in result) { var itemForUpdate = CaseCommunicationItems.SingleOrDefault( comItem => comItem.CommunicationItemId == item.CommunicationItemId); if (itemForUpdate == null) { item.CaseId = InnerItem.CaseId; CaseCommunicationItems.Add(item); repository.Add(item); } } //if messsage was writed in textbox, but Enter was not pressed //then create new publicReplyItem and save it; if (!string.IsNullOrEmpty(CaseCommunications.NewBody)) { var activeCommand = CaseCommunications.ToolBarCommmands.SingleOrDefault(c => c.IsActive); if ((CommunicationItemType)activeCommand.CommandParametr == CommunicationItemType.PublicReply) { PublicReplyItem publicReplyItem = new PublicReplyItem(); publicReplyItem.AuthorName = _authorName; publicReplyItem.Body = CaseCommunications.NewBody; publicReplyItem.Title = InnerItem.Title; publicReplyItem.Created = (DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Local)).ToUniversalTime(); publicReplyItem.LastModified = publicReplyItem.Created; publicReplyItem.CaseId = InnerItem.CaseId; CaseCommunicationItems.Add(publicReplyItem); repository.Add(publicReplyItem); } OnUIThread(() => { if (activeCommand != null) { activeCommand.Command.Execute(CaseCommunications.NewBody); } }); } } }