public void Put(Guid id, [FromBody] PortsOfEntry value)
        {
            var entity = this.dataContext.Ports.First(x => x.Id == id);

            PortOfEntry.CopyPropertyValues(value, entity);
            this.dataContext.Update(entity);
            this.dataContext.SaveChanges();
        }
Beispiel #2
0
 internal static PortOfEntry FromApiModel(PortsOfEntry dataModel)
 {
     return(new PortOfEntry
     {
         Id = dataModel.Id,
         Label = dataModel.ItemsLabels,
         Latitude = dataModel.ItemsLatitudes,
         Longitude = dataModel.ItemsLongitudes
     });
 }
        public ActionResult <PortsOfEntry> Post([FromBody] PortsOfEntry value)
        {
            var  dataObject = PortOfEntry.FromApiModel(value);
            Guid newId      = Guid.NewGuid();

            dataObject.Id = newId;
            this.dataContext.Ports.Add(dataObject);
            this.dataContext.SaveChanges();
            var result = PortsOfEntry.FromDataModel(
                this.dataContext.Ports.First(x => x.Id == newId)
                );
            var resultUrl = string.Concat(configuration["SwaggerBaseUrl"], $"/PortsOfEntry/{newId}");

            return(Created(resultUrl, result));
        }
 public IEnumerable <PortsOfEntry> Get()
 {
     return(this.dataContext.Ports
            .OrderBy(x => x.Label)
            .Select(x => PortsOfEntry.FromDataModel(x)));
 }
Beispiel #5
0
 internal static void CopyPropertyValues(PortsOfEntry from, PortOfEntry to)
 {
     to.Label     = from.ItemsLabels;
     to.Latitude  = from.ItemsLatitudes;
     to.Longitude = from.ItemsLongitudes;
 }