public async Task <IActionResult> Post(CarModel carModelModel) { if (carModelModel.Name == null) { return(BadRequest()); } CarModel carModel = carModelService.Add(carModelModel); return(Ok(carModel)); }
private static void DbInitialize() { Role adminRole = new Role { Name = "Admin", ContentManager = true, UserAdmin = true, Seller = true, Сourier = true }; Role contentManager = new Role { Name = "ContentManager", ContentManager = true, UserAdmin = false, Seller = false, Сourier = false }; RoleService roleService = new RoleService(); roleService.Add(adminRole); roleService.Add(contentManager); roleService.Add(new Role { Name = "Courier", ContentManager = false, UserAdmin = false, Seller = false, Сourier = true }); roleService.Add(new Role { Name = "Seller", ContentManager = false, UserAdmin = false, Seller = true, Сourier = false }); roleService.Add(new Role { Name = "Customer", ContentManager = false, UserAdmin = false, Seller = false, Сourier = false }); //adminRole.Id = contentManager.Id = 0; //RoleService roleService = new RoleService(); //var adminRole = roleService.GetAll().FirstOrDefault(x => x.UserAdmin == true); //var contentManager = roleService.GetAll().FirstOrDefault(x => x.UserAdmin == false); User adminUser = new User { Login = "******", Password = "******", RoleId = adminRole.Id }; User contentUser = new User { Login = "******", Password = "******", RoleId = contentManager.Id }; AccountService accountService = new AccountService(); accountService.Add(adminUser); accountService.Add(contentUser); CarBrand renault = new CarBrand { Name = "Ranault", ImagePath = "test1" }; CarBrand citroen = new CarBrand { Name = "Citroen", ImagePath = "test2" }; CarBrand peugeot = new CarBrand { Name = "Peugeot", ImagePath = "test3" }; CarBrand bugatti = new CarBrand { Name = "Bugatti", ImagePath = "test4" }; CarBrandService carBrandService = new CarBrandService(); carBrandService.Add(renault); carBrandService.Add(citroen); carBrandService.Add(peugeot); carBrandService.Add(bugatti); CarModel logan = new CarModel { Name = "Logan", CarBrandId = renault.Id }; CarModel stepway = new CarModel { Name = "Stepway", CarBrandId = renault.Id }; CarModel kaptur = new CarModel { Name = "Kaptur", CarBrandId = renault.Id }; CarModel koleos = new CarModel { Name = "Koleos", CarBrandId = renault.Id }; CarModelService carModelService = new CarModelService(); carModelService.Add(logan); carModelService.Add(stepway); carModelService.Add(kaptur); carModelService.Add(koleos); Console.WriteLine("DB has been initialized"); }