public async Task <BaseComponentResultRp> UpdateCustomer(int id, CustomerPutRp model) { var result = new BaseComponentResultRp(); var createdBy = this._identityGateway.GetIdentity(); this._dbContext.ChangeTracker.AutoDetectChangesEnabled = true; var customer = await this._dbContext.Customers.SingleAsync(c => c.Id == id); if (customer == null) { result.AddNotFound($"The Resource {id} doesn't exists."); return(result); } customer.Update(this._datetimeGateway.GetCurrentDateTime(), createdBy, model.Name, model.Avatar, model.Leaders); this._dbContext.Update(customer); await this._dbContext.SaveChangesAsync(); return(result); }
public void then_update() { NewValue = Faker.Company.Name(); var representationPut = new CustomerPutRp(); representationPut.Name = NewValue; var jsonContent = HttpClientExtension.ParseModelToHttpContent(representationPut); var responsePut = _client.PutAsync(NewResourceLocation, jsonContent).Result; Assert.Equal(StatusCodes.Status200OK, (int)responsePut.StatusCode); }
public async Task <IActionResult> Put(int id, [FromBody] CustomerPutRp resource) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var response = await this._customerComponent.UpdateCustomer(id, resource); if (response.HasNotFounds()) { return(this.NotFound(response.GetNotFounds())); } if (response.HasConflicts()) { return(this.Conflict(response.GetConflicts())); } return(this.Ok()); }