public async Task CreateAutomobileAsync(MainCreateInputModel model) { var makeId = await this.dbContext.Makes //TODO maybe add another method that uses select list item so you dont have to use string search .Where(x => x.Name == model.PrimaryProperties.Make) .Select(x => x.Id) .FirstOrDefaultAsync(); var modelId = await this.dbContext.Models .Where(x => x.Name == model.PrimaryProperties.Model) .Select(x => x.Id) .FirstOrDefaultAsync(); Automobile automobile = this.mapper.Map <Automobile>(model); automobile.MakeId = makeId; automobile.ModelId = modelId; automobile.CreatedOn = DateTime.UtcNow; automobile.UserId = this.userService.GetLoggedInUserId(); automobile.Images = await imagesHelper.SetAutomobileImages(model.Images, this.cloudinary); //TODO add images await dbContext.Automobiles.AddAsync(automobile); await dbContext.SaveChangesAsync(); }
public async Task <IActionResult> Create(MainCreateInputModel inputModel) { await this.autoService.CreateAutomobileAsync(inputModel); return(this.View(inputModel)); }