public HttpResponseMessage Update(UpdateCustomerModel model) { try { Customer customer = _customerRepository.GetById(model.Id); if (customer == null) { throw new BusinessException("Customer with such Id is not found: " + model.Id); } Industry industry = _industryRepository.GetByName(model.Industry); if (industry == null) { throw new BusinessException("Industry name is invalid: " + model.Industry); } customer.UpdateIndustry(industry); _unitOfWork.Commit(); return(Request.CreateResponse(HttpStatusCode.OK, Envelope.Ok())); } catch (BusinessException ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest, Envelope.Error(ex.Message))); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, Envelope.Error(ex.Message))); } }
public IActionResult Alter(CustomerView customer) { UpdateCustomerModel update = new UpdateCustomerModel(customer.Id , customer.Name , customer.Phone); if (update.Invalid) { ViewData["IdError"] = update.Notifications .Where(w => w.Property == "Id")? .FirstOrDefault()? .Message; ViewData["NameError"] = update.Notifications .Where(w => w.Property == "Name")? .FirstOrDefault()? .Message; ViewData["PhoneError"] = update.Notifications .Where(w => w.Property == "Phone")? .FirstOrDefault()? .Message; ViewData["Customer"] = customer ?? new CustomerView(); return(View("Edit")); } ViewData["CustomerView"] = _mapper.Map <CustomerView>(_customerService.Update(update)); return(View()); }
public async Task <ActionResult <Customer> > Customer([FromBody] UpdateCustomerModel updateCustomerModel) { try { var customer = await _mediator.Send(new GetCustomerByIdQuery { Id = updateCustomerModel.Id }); if (customer == null) { return(BadRequest($"No customer found with the id {updateCustomerModel.Id}")); } if (updateCustomerModel.Age > 0) { updateCustomerModel.Age = -1; } return(await _mediator.Send(new UpdateCustomerCommand { Customer = _mapper.Map(updateCustomerModel, customer) })); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public MappingProfileTests() { var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MappingProfile()); }); _mapper = mockMapper.CreateMapper(); _createCustomerModel = new CreateCustomerModel { FirstName = "FirstName", LastName = "LastName", Birthday = new DateTime(1989, 11, 23), Age = 30 }; _updateCustomerModel = new UpdateCustomerModel { Id = Guid.Parse("9f35b48d-cb87-4783-bfdb-21e36012930a"), FirstName = "FirstName", LastName = "LastName", Birthday = new DateTime(1989, 11, 23), Age = 30 }; }
public void VerifyCustomerServiceUpdateResponse() { WaitForKafkaResponseAfterUpdate(); if (UpdateCustomerModel.CustomerName != null) { Assert.AreEqual(UpdateCustomerModel.CustomerName, customerServiceUpdateResponse.UpdateCustomerEvent.CustomerName); } if (UpdateCustomerModel.DealerNetwork != null) { Assert.AreEqual(UpdateCustomerModel.DealerNetwork, customerServiceUpdateResponse.UpdateCustomerEvent.DealerNetwork); } if (UpdateCustomerModel.NetworkDealerCode != null) { Assert.AreEqual(UpdateCustomerModel.NetworkDealerCode, customerServiceUpdateResponse.UpdateCustomerEvent.NetworkDealerCode); } if (UpdateCustomerModel.NetworkCustomerCode != null) { Assert.AreEqual(UpdateCustomerModel.NetworkCustomerCode, customerServiceUpdateResponse.UpdateCustomerEvent.NetworkCustomerCode); } if (UpdateCustomerModel.DealerAccountCode != null) { Assert.AreEqual(UpdateCustomerModel.DealerAccountCode, customerServiceUpdateResponse.UpdateCustomerEvent.DealerAccountCode); } if (UpdateCustomerModel.CustomerUID != null) { Assert.AreEqual(UpdateCustomerModel.CustomerUID, customerServiceUpdateResponse.UpdateCustomerEvent.CustomerUID); } if (UpdateCustomerModel.ActionUTC != null) { Assert.AreEqual(UpdateCustomerModel.ActionUTC.ToString("yyyyMMddHHmmss"), customerServiceUpdateResponse.UpdateCustomerEvent.ActionUTC.ToString("yyyyMMddHHmmss")); } customerServiceUpdateResponse = null; // Reassigning the response back to null }
public CustomerControllerTests() { var mapper = A.Fake <IMapper>(); _mediator = A.Fake <IMediator>(); _testee = new CustomerController(mapper, _mediator); _createCustomerModel = new CreateCustomerModel { FirstName = "FirstName", LastName = "LastName", Birthday = new DateTime(1989, 11, 23), Age = 30 }; _updateCustomerModel = new UpdateCustomerModel { Id = _id, FirstName = "FirstName", LastName = "LastName", Birthday = new DateTime(1989, 11, 23), Age = 30 }; var customer = new Customer { Id = _id, FirstName = "FirstName", LastName = "LastName", Birthday = new DateTime(1989, 11, 23), Age = 30 }; A.CallTo(() => mapper.Map <Customer>(A <Customer> ._)).Returns(customer); A.CallTo(() => _mediator.Send(A <CreateCustomerCommand> ._, default)).Returns(customer); A.CallTo(() => _mediator.Send(A <UpdateCustomerCommand> ._, default)).Returns(customer); }
public async Task <IActionResult> Update([FromBody] UpdateCustomerModel updateCustomerModel) { //TODO: Use AutoMapper for mappings var existCustomer = await _mediator.Send(new GetCustomerByIdQuery { Id = updateCustomerModel.Id }); if (existCustomer == null) { return(BadRequest($"No customer found with the id {updateCustomerModel.Id}")); } var customer = new Customer() { Id = updateCustomerModel.Id, FirstName = updateCustomerModel.FirstName, LastName = updateCustomerModel.LastName, Birthday = updateCustomerModel.Birthday, Age = updateCustomerModel.Age, Phone = updateCustomerModel.Phone, }; var result = await _mediator.Send(new UpdateCustomerCommand { Customer = customer }); return(Ok(result)); }
public async Task <IActionResult> Execute(int customerId, UpdateCustomerModel data) { var customer = await _db.Set <Customer>().SingleAsync(p => p.Id == customerId); customer.Update(name: data.Name); await _db.SaveChangesAsync(); return(NoContent()); }
public IActionResult Update(UpdateCustomerModel model) { Result <Customer> customerResult = _customerRepository.GetById(model.Id) .ToResult("Customer with such Id is not found: " + model.Id); Result <Industry> industryResult = Industry.Get(model.Industry); return(Result.Combine(customerResult, industryResult) .OnSuccess(() => customerResult.Value.UpdateIndustry(industryResult.Value)) .OnBoth(result => result.IsSuccess ? Ok() : Error(result.Error))); }
public async Task <IActionResult> UpdateCustomer(string invoiceId, [FromBody] UpdateCustomerModel data) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _InvoiceRepository.UpdateInvoice(invoiceId, data).ConfigureAwait(false); return(Ok()); }
public HttpResponseMessage Update(UpdateCustomerModel model) { var customerResult = customerRepository.GetById(model.Id) .ToResult("Customer with such Id is not found: " + model.Id); var industryResult = Industry.Get(model.Industry); return(Result.Combine(customerResult, industryResult) .OnSuccess(() => customerResult.Value.UpdateIndustry(industryResult.Value)) .OnBoth(result => result.IsSuccess ? Ok() : Error(result.Error))); }
public HttpResponseMessage Update(UpdateCustomerModel model) { Result <Customer> customerResult = _customerRepository.GetById(model.Id) .ToResult("Customer with such Id is not found: " + model.Id); Result <Industry> industryResult = Industry.Get(model.Industry); return(Result.Combine(customerResult, industryResult) .Tap(() => customerResult.Value.UpdateIndustry(industryResult.Value)) .Finally(result => result.IsSuccess ? Ok() : Error(result.Error))); }
public async Task <IActionResult> Update(string id, [FromBody] UpdateCustomerModel customer) { if (customer == null || customer.Id != id) { return(BadRequest()); } return(Ok(await Mediator.Send(new UpdateCustomerCommand { Customer = customer }))); }
public async Task <IActionResult> PutCustomer([FromRoute] string id, [FromBody] UpdateCustomerModel customer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _updateCustomerCommand.Execute(customer); return(NoContent()); }
public async Task ItShouldReturnNoContent() { var customerId = await _fixture.CreateCustomer(); var data = new UpdateCustomerModel { Name = "New name" }; var response = await _fixture.Put($"api/customers/{customerId}", data); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); }
public void ShouldReturnSuccessWhenUpdateCustomer() { // Arrange var customerInputModel = new UpdateCustomerModel(1, "Daniel", "Negrisoli Batista", new DateTime(1980, 1, 1)); var customerService = new CustomerService(this.CustomerRepositoryMock); // Act var customer = customerService.UpdateCustomer(1, customerInputModel); // Assert Assert.Equal(customerInputModel.FirstName, customer.FirstName); }
public ActionResult ChangePassword(PreferenceChangePasswordModel data) { SelectCustomerModel customerData = new SelectCustomerModel() { Email = data.email }; CustomerResultModel customerResult = customerTable.SelectRecord(customerData); if (customerResult.CustomerUUID == null) { return(Json(new { result = "Fail", reason = "Invalid Customer" })); } bool verifyPassword = Password.VerifyHash(data.oldPassword, customerResult.Hash); if (!verifyPassword) { return(Json(new { result = "Fail", reason = "Invalid Password" })); } //Generate Password's Salt and Hash byte[] salt = Password.ComputeSaltBytes(); string hashString = Password.ComputeHash(data.newPassword, salt); string saltString = Convert.ToBase64String(salt); customerResult.Hash = hashString; customerResult.Salt = saltString; UpdateCustomerModel customerUpdate = new UpdateCustomerModel() { CustomerUUID = customerResult.CustomerUUID, Email = customerResult.Email, FirstName = customerResult.FirstName, LastName = customerResult.LastName, Hash = customerResult.Hash, Salt = customerResult.Salt, Phone = customerResult.Phone }; NonQueryResultModel updateResult = customerTable.UpdateRecord(customerUpdate); if (updateResult.Success) { return(Json(new { result = "Success" })); } else { return(Json(new { result = "Fail", reason = "Password was not updated" })); } }
public async Task <ActionResult> Update(Guid uuid, UpdateCustomerModel model) { var(customer, uuids) = model.GetCustomer(uuid); var result = await _customerService.SaveAsync(customer, uuids); if (!result.IsSuccessful) { return(FailResult(result)); } if (await _unitOfWork.SaveChangesAsync()) { return(NoContent()); } return(ErrorResult()); }
public async Task ShouldUpdateCustomerInDatabase() { var command = new UpdateCustomerCommand(_context); var model = new UpdateCustomerModel { CustomerId = "JASON", CompanyName = "Jason Inc", ContactName = "Jason Taylor" }; await command.Execute(model); var entity = await _context.Customers.FindAsync("JASON"); Assert.Equal("Jason Inc", entity.CompanyName); }
public async Task <ActionResult> Update(string id, [FromBody] UpdateCustomerModel model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _customerUpdateContext.Execute(model); return(new NoContentResult()); }
public async Task <IActionResult> Update(string id, [FromBody] UpdateCustomerModel customer) { if (customer == null || customer.Id != id) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _updateCustomerCommand.Execute(customer); return(new NoContentResult()); }
public async Task UpdateInvoice(string invoiceId, UpdateCustomerModel data) { using var ctx = _applicationDbContextFactory.CreateContext(); var invoiceData = await ctx.Invoices.FindAsync(invoiceId).ConfigureAwait(false); if (invoiceData == null) { return; } if (invoiceData.CustomerEmail == null && data.Email != null) { invoiceData.CustomerEmail = data.Email; AddToTextSearch(ctx, invoiceData, invoiceData.CustomerEmail); } await ctx.SaveChangesAsync().ConfigureAwait(false); }
public Tuple <long, string> UpdateCustomer(UpdateCustomerModel customer) { string[] LogoArr = customer.Logo.Split(','); string customerLogo = ""; if (LogoArr.Length > 1) { customerLogo = LogoArr[1]; } int?reportId = null; if (customer.ReportStyleId != 0) { reportId = customer.ReportStyleId; } var customerEntity = _context.CUSTOMER.Where(c => c.customer_auto == customer.CustomerId).FirstOrDefault(); if (customerEntity == null) { return(Tuple.Create(Convert.ToInt64(-1), "Couldn't find a customer with this ID.")); } customerEntity.cust_name = customer.CustomerName; customerEntity.custid = customer.CustomerName; customerEntity.DealershipId = customer.DealershipId; customerEntity.cust_phone = customer.PhoneNumber; customerEntity.cust_email = customer.Email; customerEntity.fullAddress = customer.Address; if (customerLogo.Trim() != "") { customerEntity.logo = Convert.FromBase64String(customerLogo); } customerEntity.SelectedReportId = customer.ReportStyleId; customerEntity.QuoteReportStyle = customer.QuoteReportStyleId; customerEntity.DefaultHourlyRate = customer.HourlyLabourCost; try { _context.SaveChanges(); } catch (Exception e) { return(Tuple.Create(Convert.ToInt64(-1), e.Message)); } return(Tuple.Create(customerEntity.customer_auto, "Successfully updated customer. ")); }
public CustomerControllerTests() { var mapper = A.Fake <IMapper>(); _mediator = A.Fake <IMediator>(); _testee = new CustomerController(mapper, _mediator); _createCustomerModel = new CreateCustomerModel { FirstName = "FirstName", LastName = "LastName", Birthday = new DateTime(1989, 11, 23), Age = 30 }; _updateCustomerModel = new UpdateCustomerModel { Id = _id, FirstName = "FirstName", LastName = "LastName", Birthday = new DateTime(1989, 11, 23), Age = 30 }; var customer = new List <Customer> { new Customer { Id = _id, FirstName = "FirstName", LastName = "LastName", Birthday = new DateTime(1989, 11, 23), Age = 30 }, new Customer { Id = Guid.Parse("654b7573-9501-436a-ad36-94c5696ac28f"), FirstName = "Darth", LastName = "Vader", Birthday = new DateTime(1977, 05, 25), Age = 43 } }; A.CallTo(() => mapper.Map <Customer>(A <Customer> ._)).Returns(customer.First()); A.CallTo(() => _mediator.Send(A <CreateCustomerCommand> ._, default)).Returns(customer.First()); A.CallTo(() => _mediator.Send(A <UpdateCustomerCommand> ._, default)).Returns(customer.First()); A.CallTo(() => _mediator.Send(A <GetCustomersQuery> ._, default)).Returns(customer); }
public async Task UpdateInvoice(string invoiceId, UpdateCustomerModel data) { using (var ctx = _ContextFactory.CreateContext()) { var invoiceData = await ctx.Invoices.FindAsync(invoiceId).ConfigureAwait(false); if (invoiceData == null) { return; } if (invoiceData.CustomerEmail == null && data.Email != null) { invoiceData.CustomerEmail = data.Email; } await ctx.SaveChangesAsync().ConfigureAwait(false); } }
public void Handle(PayloadMessage message) { try { if (message.Value == null || message.Value == "null") { LogResult.Report(Log, "log_ForInfo", "Kafka Message is Null"); return; } if (CreateCustomerModel != null && CreateCustomerModel.ActionUTC != null) { if (CreateCustomerModel.ActionUTC.ToString() != null && message.Value.Contains(CreateCustomerModel.ActionUTC.ToString("yyyy-MM-ddTHH:mm:ss")) && message.Value.Contains(CreateCustomerModel.ReceivedUTC.ToString()) && CreateCustomerModel.CustomerUID.ToString() != null && message.Value.Contains(CreateCustomerModel.CustomerUID.ToString())) { customerServiceCreateResponse = JsonConvert.DeserializeObject <CreateCustomerModel>(message.Value); } LogResult.Report(Log, "log_ForInfo", string.Format("Response Received With Offset {0}: {1}", message.OffSet, message.Value)); if (UpdateCustomerModel != null && UpdateCustomerModel.ActionUTC != null && UpdateCustomerModel.CustomerUID != Guid.Empty) { if (UpdateCustomerModel.ActionUTC.ToString() != null && message.Value.Contains(UpdateCustomerModel.ActionUTC.ToString("yyyy-MM-ddTHH:mm:ss")) && message.Value.Contains(UpdateCustomerModel.ReceivedUTC.ToString()) && UpdateCustomerModel.CustomerUID.ToString() != null && message.Value.Contains(UpdateCustomerModel.CustomerUID.ToString())) { customerServiceUpdateResponse = JsonConvert.DeserializeObject <UpdateCustomerModel>(message.Value); } LogResult.Report(Log, "log_ForInfo", string.Format("Response Received With Offset {0}: {1}", message.OffSet, message.Value)); } if (DeleteCustomerModel != null && DeleteCustomerModel.ActionUTC != null && DeleteCustomerModel.CustomerUID != Guid.Empty) { if (DeleteCustomerModel.ActionUTC.ToString() != null && message.Value.Contains(DeleteCustomerModel.ActionUTC.ToString("yyyy-MM-ddTHH:mm:ss")) && message.Value.Contains(DeleteCustomerModel.ReceivedUTC.ToString()) && DeleteCustomerModel.CustomerUID.ToString() != null && message.Value.Contains(DeleteCustomerModel.CustomerUID.ToString())) { customerServiceDeleteResponse = JsonConvert.DeserializeObject <DeleteCustomerModel>(message.Value); } LogResult.Report(Log, "log_ForInfo", string.Format("Response Received With Offset {0}: {1}", message.OffSet, message.Value)); } } } catch (Exception e) { LogResult.Report(Log, "log_ForError", "Got Error While Handling Response", e); throw new Exception(e + "Got Error While Handling Response"); } }
public CustomerModel UpdateCustomer(int id, UpdateCustomerModel updateCustomerModel) { Customer customer = _customerRepository.GetById(id); if (customer == null) { return default; } customer.FirstName = updateCustomerModel.FirstName; customer.LastName = updateCustomerModel.LastName; customer.Birthday = updateCustomerModel.Birthday; _customerRepository.Update(customer); return customer.ConvertToCustomer(); }
public IActionResult Update(UpdateCustomerModel model) { var customerResult = _customerRepository .GetById(model.Id) .ToResult("Customer with such Id is not found: " + model.Id); var industryResult = Industry.Get(model.Industry); var result = Result.Combine(customerResult, industryResult); if (result.IsFailure) { return(Error(result.Error)); } customerResult.Value.UpdateIndustry(industryResult.Value); return(Ok()); }
public ActionResult <CustomerModel> Put(int id, [FromBody] UpdateCustomerModel customerInputModel) { if (customerInputModel == null) { return(BadRequest()); } if (ModelState.IsValid) { _customerService.UpdateCustomer(id, customerInputModel); return(NoContent()); } else { return(BadRequest()); } }
public void Update_updates_a_customer_if_no_validation_errors() { Customer customer = CreateCustomer("Cars"); var model = new UpdateCustomerModel { Id = customer.Id, Industry = "Other" }; Response response = Invoke(x => x.Update(model)); response.ShouldBeOk(); using (var db = new CustomerDatabase()) { db.ShouldContainCustomer(model.Id) .WithIndustry("Other") .WithEmailCampaign(EmailCampaign.Generic); } }