public async Task <string> CreateService(string carValueId, CarServiceBinding binding) { using (var context = GetMainContext()) { var entity = binding.ToEntity(context); entity.CarId = context.Cars.GetId(carValueId).Value; context.CarServices.Add(entity); await context.SaveChangesAsync(); return(entity.ValueId); } }
public static CarService ToEntity(this CarServiceBinding b, MainContext context, CarService entity = null) { if (entity == null) { entity = new CarService(); } entity.CarServiceTypeId = context.CarServiceTypes.GetId(b.TypeId).Value; entity.Date = b.Date; entity.Description = b.Description; entity.ValueId = IdHelper.Generate(); return(entity); }
public async Task <IActionResult> PostService(string id, [FromBody] CarServiceBinding binding) => Ok(await _carHandler.CreateService(id, binding));