/// <summary> /// Updates a ship /// </summary> /// <param name="id"></param> /// <param name="cmd"></param> /// <returns></returns> public async Task <Ship> Update(int id, ShipCommand cmd) { cmd.Validate <ShipCommand, ShipCommandValidator>(); var ship = await ctx.Ships.FindAsync(id); ship.Name = cmd.Name; ship.Imd = cmd.Imd; ship.Mmsi = cmd.Mmsi; ship.CustomerId = cmd.CustomerId; await ctx.SaveChangesAsync(); return(ship); }
/// <summary> /// Creates a ship /// </summary> /// <param name="cmd"></param> /// <returns></returns> public async Task <Ship> Create(ShipCommand cmd) { cmd.Validate <ShipCommand, ShipCommandValidator>(); var record = ctx.Ships.Add(new Ship { Name = cmd.Name, Imd = cmd.Imd, Mmsi = cmd.Mmsi, CustomerId = cmd.CustomerId }); await ctx.SaveChangesAsync(); return(record.Entity); }