/// <summary> /// create new model and new modelcategories and add them all to database /// </summary> /// <param name="modelToCreate"></param> /// <returns></returns> public async Task CreateModel(ModelCreateDtoModel modelToCreate) { if (modelToCreate.ImageAddress == null) { modelToCreate.ImageAddress = GlobalConstants.ImageAddress; } var brand = await this.brandService.GetBrandByNameAsync(modelToCreate.BrandName); var model = ModelServiceCreateMapper.Map(modelToCreate, brand); var allCategories = await this.categoryService.GetAllCategoriesForModelAsync(); for (int i = 0; i < allCategories.Count(); i++) { var modelCategory = new ModelCategories { Category = allCategories[i], Model = model, }; await this.modelCategories.InsertAsync(modelCategory); } await this.models.InsertAsync(model); await this.models.SaveAsync(); }
public static ModelCreateDtoModel Map(ModelInputViewModel inputViewModel) { var modelToCreate = new ModelCreateDtoModel { Name = inputViewModel.Name, StartYear = inputViewModel.StartYear, EndYear = inputViewModel.EndYear, BrandName = inputViewModel.BrandName, ImageAddress = inputViewModel.ImageAddress, }; return(modelToCreate); }
public static Model Map(ModelCreateDtoModel modelToCreate, Brand brand) { var model = new Model { Name = modelToCreate.Name, StartYear = modelToCreate.StartYear, EndYear = modelToCreate.EndYear, BrandId = brand.Id, Brand = brand, ImageAddress = modelToCreate.ImageAddress, }; return(model); }