public async Task <ActionResult> Create(CreateAdvertisementRequestModel model) { var userId = this.User.GetId(); model.AuthorId = userId; var advertisementId = await this.advertisementsService.CreateAsync(userId, model); return(Created(nameof(this.Create), advertisementId)); }
public async Task <ActionResult> Create(CreateAdvertisementRequestModel model) { var userId = User.GetId(); var advertisementId = await _advertisementService.Create( model.Name, model.Description, model.Price, userId, model.Images); return(Created(nameof(Create), advertisementId)); }
public async Task <string> CreateAsync(string userId, CreateAdvertisementRequestModel input) { input.Car.OwnerId = userId; var newCarId = await this.carsService.CreateAsync(input.Car); var newAdvertisement = new Advertisement { Title = input.Title, Description = input.Description, CarId = newCarId, AuthorId = userId, }; await this.dbContext.Advertisements.AddAsync(newAdvertisement); await this.dbContext.SaveChangesAsync(); foreach (var url in input.ImageURLs) { await this.imagesService.CreateAsync(url, newAdvertisement.Id); } await this.carsService.SetCarsAdvertisementAsync(newCarId, newAdvertisement.Id); if (!string.IsNullOrEmpty(input.PhoneNumber)) { await this.usersService.SetUserPhoneNumberIfNull(userId, input.PhoneNumber); } if (!string.IsNullOrEmpty(input.Location)) { await this.usersService.SetUserLocationIfNull(userId, input.Location); } return(newAdvertisement.Id); }