internal static Representative FromApiModel(RepresentativeData apiModel) { return(new Representative { Id = apiModel.Id, RepContact = apiModel.RepContact, RepEmail = apiModel.RepEmail, RepLocation = apiModel.RepLocation, RepName = apiModel.RepName }); }
public void Put(Guid id, [FromBody] RepresentativeData value) { var entity = this.dataContext.Representatives.First(x => x.Id == id); entity.RepContact = value.RepContact; entity.RepEmail = value.RepEmail; entity.RepLocation = value.RepLocation; entity.RepName = value.RepName; this.dataContext.Update(entity); this.dataContext.SaveChanges(); }
public ActionResult <RepresentativeData> Post([FromBody] RepresentativeData value) { var dataObject = Representative.FromApiModel(value); Guid newId = Guid.NewGuid(); dataObject.Id = newId; this.dataContext.Representatives.Add(dataObject); this.dataContext.SaveChanges(); var result = RepresentativeData.FromDataModel( this.dataContext.Representatives.First(x => x.Id == newId) ); var resultUrl = string.Concat(configuration["SwaggerBaseUrl"], $"/RepresentativeData/{newId}"); return(Created(resultUrl, result)); }
public IEnumerable <RepresentativeData> Get() { return(this.dataContext.Representatives .OrderBy(x => x.RepName) .Select(x => RepresentativeData.FromDataModel(x))); }