Ejemplo n.º 1
0
        public void DeleteCar(int carId)
        {
            var car = _carRepository.GetCar(carId);

            _carRepository.DeleteCar(car);
            _carRepository.Save();
        }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirmed(int customerId, int carId)
        {
            Car car = carsRepo.GetCarByCustomerId(customerId, carId);

            if (car == null)
            {
                return(HttpNotFound());
            }

            // delete car's jobs first
            car.Jobs.ToList().ForEach(j =>
            {
                var job = jobsRepo.GetJobById(customerId, carId, j.JobId);
                // delete the job's children first
                job.SpareParts.ToList().ForEach(sp =>
                {
                    var sparePart = sparePartsRepo.GetSparePartById(job.JobId, sp.SparePartId);
                    sparePartsRepo.DeleteSparePart(sparePart.SparePartId);
                });
                sparePartsRepo.Save();

                //then delete the job itself
                jobsRepo.DeleteJob(job.JobId);
                jobsRepo.Save();
            });

            // then delete the car itself
            carsRepo.DeleteCar(carId);
            carsRepo.Save();

            return(RedirectToAction("CarsByCustomer", customerId));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> DeleteCar(int id)
        {
            try
            {
                var car = await _repo.GetCar(id);

                if (car == null)
                {
                    return(NotFound());
                }

                _repo.DeleteCar(car);

                if (await _repo.SaveChangesAsync())
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Ejemplo n.º 4
0
        public IHttpActionResult DeleteCar(int userId, int id)
        {
            try
            {
                if (!_userRepository.UserExists(userId))
                {
                    return(NotFound());
                }

                var car = _carRepository.GetCarForUser(userId, id, false);

                if (car == null)
                {
                    return(NotFound());
                }

                _carRepository.DeleteCar(car);

                if (!_appRepository.Commit())
                {
                    return(InternalServerError());
                }

                return(StatusCode(HttpStatusCode.NoContent));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
        public void Should_Return_True_After_Delete_Car()
        {
            //validate
            var car    = CarRepository.FindCarById(1);
            var result = CarRepository.DeleteCar(car);

            Assert.IsTrue(result);
        }
Ejemplo n.º 6
0
 public void DeleteCar(int id)
 {
     if (id < 1)
     {
         throw new InvalidOperationException("Car Id needs to be larger then 0");
     }
     _carRepository.DeleteCar(id);
 }
Ejemplo n.º 7
0
 public Car Delete(int id)
 {
     if (id < 1)
     {
         throw new InvalidDataException("ID must be higher than one! Otherwise, you failed!");
     }
     return(_carRepo.DeleteCar(id));
 }
Ejemplo n.º 8
0
        public IActionResult DeleteConfirmed(int id)
        {
            Car car = carRepository.GetCarByID(id);

            carRepository.DeleteCar(car.CarID);
            carRepository.Save();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 9
0
        public Car DeleteCar(Car carToDelete)
        {
            if (carToDelete == null)
            {
                throw new InvalidDataException("The car you are trying to delete does not exist");
            }

            return(_carRepository.DeleteCar(carToDelete.CarId));
        }
Ejemplo n.º 10
0
        public bool DeleteCar(Car car)
        {
            var result = _carRepository.DeleteCar(car);

            if (result > 0)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 11
0
        public ActionResult Delete(int carId)
        {
            Car deletedCar = repository.DeleteCar(carId);

            if (deletedCar != null)
            {
                TempData["message"] = string.Format("Запись \"{0}\" была удалена", deletedCar.Name);
            }
            return(RedirectToAction("List"));
        }
Ejemplo n.º 12
0
        public IActionResult OnPost()
        {
            var DeletedCar = carRepository.DeleteCar(Car.Id);

            if (DeletedCar == null)
            {
                return(RedirectToPage("/Error"));
            }
            return(RedirectToPage("/Cars/Index"));
        }
Ejemplo n.º 13
0
        public ActionResult Delete(int carID)
        {
            Car deletedCar = repository.DeleteCar(carID);

            if (deletedCar != null)
            {
                TempData["message"] = string.Format("Usunięto {0}", deletedCar.CarBrand);
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 14
0
        public IActionResult DeleteCar(int carId)
        {
            Car deletedCar = repository.DeleteCar(carId);

            if (deletedCar != null)
            {
                TempData["message"] = $"{deletedCar.Model} was deleted";
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 15
0
        public ActionResult Delete(int Id)
        {
            Car deletedCar = repository.DeleteCar(Id);

            /*if (deletedCar != null)
             * {
             *  TempData["message"] = string.Format("Usunięto pojazd {0}", deletedCar);
             * }*/

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 16
0
 public async Task Delete(int id)
 {
     try
     {
         await _repository.DeleteCar(id);
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error while deleting a car. [{e.Message}]");
     }
 }
Ejemplo n.º 17
0
        public bool DeleteCarById(int id)
        {
            var car = _carRepository.FindCarById(id);

            if (car == null)
            {
                return(false);
            }
            bool deleteCarSuccess = _carRepository.DeleteCar(car);

            return(deleteCarSuccess);
        }
Ejemplo n.º 18
0
 public string RemoveCar(User user)
 {
     try {
         var car = Dbc.GetCarById(user.CarId);
         user.CarId = -1;
         Dbc.DeleteCar(car);
         Dbu.UpdateUser(user);
         return("Car Removed From User Account...");
     } catch (Exception e) {
         return(e.Message);
     }
 }
Ejemplo n.º 19
0
 public ActionResult Delete(int id, Car car)
 {
     try
     {
         carRepo.DeleteCar(id);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Ejemplo n.º 20
0
        public IActionResult Delete(int id)
        {
            var car = _carRepository.GetCarById(id);

            if (car == null)
            {
                return(NotFound());
            }

            _carRepository.DeleteCar(car);
            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 21
0
        public IActionResult DeleteCar(Guid id)
        {
            var carFromRepo = _carRepository.GetCar(id);

            if (carFromRepo == null)
            {
                return(NotFound());
            }
            _carRepository.DeleteCar(carFromRepo);
            if (!_carRepository.Save())
            {
                throw new Exception("Error at Save");
            }
            return(NoContent());
        }
Ejemplo n.º 22
0
        public IActionResult DeleteConfirmed(int id, string imageUrl)
        {
            var car = carRepository.GetOneCarById(id);

            carRepository.DeleteCar(car);

            var webRoot   = env.WebRootPath;
            var imagePath = Path.Combine(webRoot.ToString() + imageUrl);

            if (System.IO.File.Exists(imagePath))
            {
                System.IO.File.Delete(imagePath);
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 23
0
 public ActionResult Delete(int id)
 {
     if (_orderRepository.Orders.Where(x => ((x.CarId == id) && (x.Status == OrderStatus.InProgress))).Count() > 0)
     {
         TempData["message"] = string.Format("Car was not deleted: order in progress exists");
     }
     else
     {
         Car deletedCar = _repository.DeleteCar(id);
         if (deletedCar != null)
         {
             TempData["message"] = string.Format("{0} was deleted", deletedCar.VIN);
         }
     }
     return(RedirectToAction("List"));
 }
Ejemplo n.º 24
0
        public IActionResult Delete(Guid id)
        {
            var car = _carRepository.GetCar(id);

            if (car == null)
            {
                return(NotFound());
            }

            _carRepository.DeleteCar(car);
            if (!_carRepository.Save())
            {
                throw new Exception($"Deleting car {id} failed on save.");
            }

            return(NoContent());
        }
Ejemplo n.º 25
0
        public async Task <Car> DeleteCar(int enterpriseId, int carId)
        {
            try
            {
                var temp = await repo.DeleteCar(enterpriseId, carId);

                if (temp != null)
                {
                    await unitOfWork.CompleteAsync();
                }
                return(temp);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 26
0
        public ActionResult DeleteCar(int id, [FromQuery] int key)
        {
            if (!ManagementHelper.IsAdministrator(key))
            {
                return(Forbid());
            }

            try
            {
                _carRepository.DeleteCar(id);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(Ok());
        }
Ejemplo n.º 27
0
        public ActionResult Delete(int CarId)
        {
            var car = repository.Cars.First(c => c.CarID == CarId);

            if (car.Hired == true)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                var deletedCar = repository.DeleteCar(CarId);
                if (deletedCar != null)
                {
                    TempData["massage"] = string.Format("Usunięto {0}", deletedCar.Model);
                }
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 28
0
 public JsonResult DeleteCar(int pk)
 {
     if (Session["role"] == null)
     {
         Session["userId"] = null;
         Session["role"] = null;
         return Json(false, JsonRequestBehavior.AllowGet);
     }
     else if (Session["role"].ToString() == "Super Admin")
     {
         return Json(carRepository.DeleteCar(pk), JsonRequestBehavior.AllowGet);
     }
     else
     {
         Session["userId"] = null;
         Session["role"] = null;
         return Json(false, JsonRequestBehavior.AllowGet);
     }
 }
Ejemplo n.º 29
0
        public async Task <IActionResult> DeleteCar(int carid)
        {
            var oldcar = await _carRepository.GetCar(carid);

            var result = await _carRepository.DeleteCar(carid);

            if (result)
            {
                // delete image
                var uploads  = Path.Combine(_hostingEnvironment.WebRootPath, "images");
                var filePath = Path.Combine(uploads, oldcar.ImageName);
                if (System.IO.File.Exists(filePath))
                {
                    System.IO.File.Delete(filePath);
                }
                return(Ok(result));
            }
            else
            {
                return(BadRequest(ResponseCodes.ErrorToDelete));
            }
        }
Ejemplo n.º 30
0
        public IActionResult Delete(Car Car)
        {
            if (Car.Id != 0)
            {
                //delete pictures
                var webRoot  = _env.WebRootPath;
                var pictures = _pictureRepository.GetPicturesByCarId(Car.Id);
                if (pictures != null && pictures.Count > 0)
                {
                    foreach (var pic in pictures)
                    {
                        var filePath = Path.Combine(webRoot.ToString() + pic.PictureUrl);
                        System.IO.File.Delete(filePath);
                    }
                }
                var car = _carRepository.GetCarById(Car.Id);
                _carRepository.DeleteCar(car);

                return(RedirectToAction(nameof(Manage)));
            }
            return(RedirectToAction(nameof(Manage)));
        }