public async Task <IActionResult> Edit(CarVM carVM) { if (!ModelState.IsValid) { return(View(carVM)); } bool result; var car = _mapper.Map <Car>(carVM); if (car.Id != 0) { result = await _repository.UpdateCar(car); } else { result = await _repository.AddCar(car); } if (result) { _toastNotification.AddSuccessToastMessage("Editing was successful"); } else { _toastNotification.AddErrorToastMessage("It was unsuccessful"); } return(RedirectToAction("Index")); }
public IActionResult CreateCar([FromBody] Car carModel) { EnsureArg.IsNotNull(carModel); carService.AddCar(carModel); return(Ok()); //return CreatedAtRoute() }
public void AddCar() { Console.WriteLine("Lägg till en ny bil (lämna tomt för att avbryta)"); Console.Write("Märke: "); var brand = Console.ReadLine(); if (string.IsNullOrEmpty(brand)) { Console.WriteLine("Avbryter"); return; } Console.Write("Modell: "); var model = Console.ReadLine(); Console.Write("Registreringsnummer: "); var reg = Console.ReadLine(); var car = new Car { Brand = brand, Model = model, LicensePlate = reg, }; _carRepository.AddCar(car); Console.WriteLine("Bilen lades till i registret."); }
public async Task <IActionResult> Create(CreateLotViewModel model) { if (ModelState.IsValid) { Car car = new Car { Name = model.Name, Desc = model.Desc, Year = model.Year, Mileage = model.Milleage, Transmission = (ushort)CarData.transmission.IndexOf(model.Transmission), Fuel = (ushort)CarData.fuel.IndexOf(model.Fuel), Body = (ushort)CarData.body.IndexOf(model.Body), Drive = (ushort)CarData.drive.IndexOf(model.Drive), EngineVolume = double.Parse(model.EngineVolume), Image = null }; User user = await _userManager.GetUserAsync(HttpContext.User); bool check = false; var roles = await _userManager.GetRolesAsync(user); if (roles.Any(r => r == "admin")) { check = true; } CarLot carLot = new CarLot { Name = model.Name, StartPrice = model.Price, Price = model.Price, Exposing = DateTime.UtcNow, Ending = DateTime.UtcNow.AddDays(model.Duration), User = await _userManager.GetUserAsync(HttpContext.User), Car = car, Applyed = check }; carRepository.AddCar(car); string src = "/images/" + car.Id + ".jpg"; using (var fileStream = new FileStream(_appEnviroment.WebRootPath + src, FileMode.Create)) { await model.Image.CopyToAsync(fileStream); } car.Image = src; carRepository.Update(car); carLotsRepository.AddLotDB(carLot); return(RedirectToAction("Actual")); } return(View()); }
public async Task <IActionResult> Create(Car car) { if (ModelState.IsValid) { _carRepository.AddCar(car); return(RedirectToAction(nameof(Index))); } return(View("Index", car)); }
public async Task AddCar(CarCreateVM carVM, string ownerId) { var car = new Car() { Model = carVM.Model, Price = carVM.Price, ReleaseDate = carVM.ReleaseDate, Series = carVM.Series }; // var carOwner = new CarOwner() { CarId = car.ID, OwnerId = Convert.ToInt32(ownerId.ToString()) }; await _carRepository.AddCar(car, Convert.ToInt32(ownerId)); }
public IActionResult Create(Car car) { if (ModelState.IsValid) { _carRepository.AddCar(car); return(RedirectToAction("Index")); } return(View(car)); }
public async Task <CarDTO> AddCar([FromForm] CarDTO carDTO) { if (carDTO.Image != null) { carDTO = await _cloudStorage.UploadFile(carDTO); } await _carRepository.AddCar(carDTO); return(carDTO); }
public IActionResult AddCar([FromBody] Car car) { if (car != null) { CarRepo.AddCar(car); //return Ok(); return(Ok(Created(car.Id.ToString(), car))); } return(BadRequest()); }
public async Task <Unit> Handle(CreateCarCommand request, CancellationToken cancellationToken) { var newCar = _mapper.Map <Car>(request); await _carRepository.AddCar(newCar); await _carRepository.UnitOfWork.SaveEntitiesAsync(); return(await Task.FromResult(Unit.Value)); }
public async Task <IActionResult> Create([Bind("Id,RegNr,CarSize,DistanceInKm")] Car car) { if (ModelState.IsValid) { car.Id = Guid.NewGuid(); _carRepository.AddCar(car); return(RedirectToAction(nameof(Index))); } return(View(car)); }
public IActionResult OnPost(Car car) { Car = carRepository.AddCar(car); if (Car != null) { return(RedirectToPage("/Cars/Index")); } return(Page()); }
public IActionResult CreateCar(Car car) { if (ModelState.IsValid) { _carRepository.AddCar(car); TempData["SM"] = "Dodałeś samochod"; return(RedirectToAction(nameof(Cars))); } TempData["CarError"] = "Nie udało dodać się auta"; return(View(car)); }
public ActionResult Add(Car newCar) { if (ModelState.IsValid) { _repo.AddCar(newCar); return(RedirectToAction("Index")); } else { return(View("Add")); } }
public async Task <IActionResult> Create([Bind("CarId,LicenseNumber,CarType")] Car car) { if (ModelState.IsValid) { car.CarId = Guid.NewGuid(); _carRepository.AddCar(car); _entityFrameworkRepository.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(car)); }
public ActionResult Add(Car newCar) { ViewBag.Message = "Add a car using the form below!"; if (ModelState.IsValid) { _repo.AddCar(newCar); return(RedirectToAction("Index")); } else { return(View("Add")); } }
public async Task <object> PostCar(AddCarToCompanyModel model) { try { await _repository.AddCar(model.Car, model.CompanyId); } catch (Exception) { return(BadRequest(new { message = "Failed to add a car." })); } return(Ok(model)); }
public async Task <CarModel> AddCar(CreateCarModel model) { _validator.Validate(model); var dbCarModel = new CarModel { Id = Guid.NewGuid().ToString(), Name = model.Name, Description = model.Description, RegistrationNumber = model.RegistrationNumber }; await _carRepository.AddCar(dbCarModel); return(dbCarModel); }
public async Task <IActionResult> Create(CarVM vm) { if (ModelState.IsValid) { var car = vm.Car; var user = await _userManager.GetUserAsync(HttpContext.User); car.UserId = user.Id; car.UserName = user.UserName; car.DateAdded = DateTime.Now; _carRepository.AddCar(car); return(RedirectToAction("AddPictures", "Pictures", new { carId = Convert.ToString(car.Id) })); } return(View(vm)); }
public async Task <Car> AddCar(AddCarParameters car) { try { var temp = await repo.AddCar(car); if (temp != null) { await unitOfWork.CompleteAsync(); } return(temp); } catch { return(null); } }
public void RegisterCar(User user, int seats, string registrationNumber) { try { Car car = new Car() { Capacity = seats, RegistrationNumber = registrationNumber }; Dbc.AddCar(car); Car carForGettingId = Dbc.GetCarByNoPlate(seats, registrationNumber); user.CarId = carForGettingId.Id; Dbu.UpdateUser(user); } catch (Exception e) { Console.WriteLine(e.Message); } }
public IActionResult CreateCar([FromBody] CarForCreationDto car) { if (car == null) { return(BadRequest()); } var carForCreation = Mapper.Map <Car>(car); _carRepository.AddCar(carForCreation); if (!_carRepository.Save()) { throw new Exception(" Saving error in Database"); } var carToReturn = Mapper.Map <CarDto>(carForCreation); //return Ok(carToReturn); return(CreatedAtRoute("GetCar", new { id = carForCreation.Id }, carToReturn)); }
public async Task Execute(CreateCarInput _input) { if (_input == null) { _outputHandler.Error("Input is null."); return; } var car = new Car() { Model = _input.Model, TypeName = _input.TypeName }; await _carRepository.AddCar(car); var carOutput = new CreateCarOutput(_input.Model, _input.TypeName); _outputHandler.Standard(carOutput); }
public async Task <AddCarResponseDto> Handle(AddCarCommand request, CancellationToken cancellationToken) { var carAdded = await _carRepository.AddCar(request); AddCarResponseDto addCarResponseDto = new AddCarResponseDto { Id = carAdded.Id, Manufacture = carAdded.Manufacture, Model = carAdded.Model, Year = carAdded.Year, Vin = carAdded.Vin, Description = carAdded.Description, Observation = carAdded.Observation, IsAvailable = carAdded.IsAvailable, StandardPrice = carAdded.StandardPrice, CarGroupId = carAdded.CarGroupId }; return(addCarResponseDto); }
public IActionResult Create(CarViewModel viewModel) { if (ModelState.IsValid) { string uniqueFileName = UploadedFile(viewModel); Car currentCar = new Car { Model = viewModel.Model, Description = viewModel.Description, Make = viewModel.Make, Trim = viewModel.Trim, Year = viewModel.Year, PurchaseDate = viewModel.PurchaseDate, PurchasePrice = viewModel.PurchasePrice, Vin = viewModel.Vin, LotDate = viewModel.LotDate, ProfilePicture = uniqueFileName, SaleDate = viewModel.SaleDate, SellingPrice = viewModel.SellingPrice, RepairCost = viewModel.RepairCost, Status = viewModel.Status }; _carRepository.AddCar(currentCar); return(RedirectToAction("Index")); } var repairCars = _repairCarRepository.GetAll(); var vmRepairCars = new CarViewModel(); foreach (var repairCar in repairCars) { vmRepairCars.ListRepairCar.Add( new SelectListItem { Text = repairCar.Description, Value = repairCar.RepairCost.ToString() }); } return(View(vmRepairCars)); }
public IActionResult Create([FromBody] Car car) { if (car == null) { return(BadRequest()); } if (_carRepository.CarExists(car.VinNo)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } _carRepository.AddCar(car); if (!_carRepository.Save()) { throw new Exception("Creating a car failed on save."); } return(CreatedAtRoute("GetCar", new { id = car.VinNo }, car)); }
public ActionResult AddNewCar([FromBody, Required] Car car, [FromQuery] int key) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!ManagementHelper.IsAdministrator(key)) { return(Forbid()); } try { _carRepository.AddCar(car); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok()); }
public async Task <IActionResult> PostCar(CarForAddDto carForAdd) { try { if (ModelState.IsValid) { var car = _mapper.Map <Car>(carForAdd); _repo.AddCar(car); if (await _repo.SaveChangesAsync()) { var newModel = _mapper.Map <CarForAddDto>(car); var location = Url.Link("GetCar", new { id = car.A_ID }); return(StatusCode(201)); } } } catch (Exception ex) { return(BadRequest(ex)); } return(BadRequest()); }
public async Task AddCar(CarDTO car) { Car newCar = _mapper.Map <CarDTO, Car>(car); await _carRepository.AddCar(newCar); }
public void AddCar(Car car) { _repository.AddCar(car); }