コード例 #1
0
        public async Task <IHttpActionResult> Post(CreateOwnerCommand owner)
        {
            var entity = Mapper.Map <Owner>(owner);

            entity.Id = Guid.NewGuid();

            _context.Owners.Add(entity);

            await _context.SaveChangesAsync();

            return(CreatedAtRoute("Owners.Get", new { id = entity.Id }, Mapper.Map <OwnerViewModel>(entity)));
        }
コード例 #2
0
        public async Task <IHttpActionResult> Post(Guid ownerId, CreateVehicleCommand vehicle)
        {
            var owner = await _context.Owners.FindAsync(ownerId);

            if (owner == null)
            {
                return(NotFound());
            }

            var entity = Mapper.Map <Vehicle>(vehicle);

            entity.Id      = Guid.NewGuid();
            entity.OwnerId = owner.Id;

            _context.Vehicles.Add(entity);
            await _context.SaveChangesAsync();

            return(CreatedAtRoute("Vehicles.GetById", new { id = entity.Id }, Mapper.Map <VehicleViewModel>(entity)));
        }
コード例 #3
0
        public async Task <IHttpActionResult> Post(Guid vehicleId, CreateFillUpCommand cmd)
        {
            var vehicle = await _context.Vehicles.FindAsync(vehicleId);

            if (vehicle == null)
            {
                return(NotFound());
            }

            if (cmd.FilledAt == null)
            {
                cmd.FilledAt = DateTime.UtcNow;
            }

            var entity = Mapper.Map <FillUp>(cmd);

            entity.Id        = Guid.NewGuid();
            entity.VehicleId = vehicleId;

            _context.FillUps.Add(entity);
            await _context.SaveChangesAsync();

            return(CreatedAtRoute("Fillups.GetById", new { id = entity.Id }, Mapper.Map <FillUpViewModel>(entity)));
        }