public void Delete()
        {
            IList <Car> l = Builder <Car> .CreateListOfSize(5).Build();

            using (ISession s = SessionFactory.OpenSession())
            {
                int count = s.QueryOver <Car>().ToRowCountQuery().FutureValue <int>().Value;
                Assert.Equal(100, count);

                using (ITransaction tx = s.BeginTransaction())
                {
                    foreach (Car x in l)
                    {
                        s.Save(x);
                    }

                    tx.Commit();

                    count = s.QueryOver <Car>().ToRowCountQuery().FutureValue <int>().Value;
                    Assert.Equal(105, count);
                }
            }

            r.Delete(l[3].ID);
            r.Delete(l[4].ID);

            using (ISession s = SessionFactory.OpenSession())
            {
                int count = s.QueryOver <Car>().ToRowCountQuery().FutureValue <int>().Value;
                Assert.Equal(103, count);
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Подтверждение автомобиля</returns>
        public IActionResult Confirm(int id)
        {
            var car = carRepository.GetAll().Where(c => c.ID.IDValue == id).ToArray()[0];

            carRepository.Delete(car);
            car.IsConfirned = true;
            car.Owner       = "Автосалон";
            carRepository.Add(car);
            return(LocalRedirect("~/Worke/OperationComplited"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Car car = _abstractRepository.GetWhere(x => x.Id == id).FirstOrDefault();

            _abstractRepository.Delete(car);
            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        /*
         * public ActionResult Create()
         * {
         *  return View();
         * }
         *
         * [HttpPost]
         * public ActionResult Create(CarViewModel carViewModel)
         * {
         *  if (ModelState.IsValid)
         *  {
         *      carViewModel.CarId = Guid.NewGuid();
         *      var car = _mapperEngine.Map<Car>(carViewModel);
         *      _carRepository.Save(car);
         *      return RedirectToAction("Index");
         *  }
         *  return View(carViewModel);
         * }
         *
         * [HttpGet]
         * public ActionResult Edit(Guid id)
         * {
         *  var car = _carRepository.GetCarBy(id);
         *  var carViewModel = _mapperEngine.Map<CarViewModel>(car);
         *  return View(carViewModel);
         * }
         *
         * [HttpPost]
         * public ActionResult Edit(CarViewModel carViewModel)
         * {
         *  if (ModelState.IsValid)
         *  {
         *      var existingCar = _carRepository.GetCarBy(carViewModel.CarId);
         *      var car = _mapperEngine.Map<Car>(carViewModel);
         *      _carRepository.Update(existingCar, car);
         *      return RedirectToAction("Index");
         *  }
         *  return View(carViewModel);
         * }*/


        public ActionResult Delete(Guid id)
        {
            var car = _carRepository.GetCarBy(id);

            _carRepository.Delete(car);
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> DeleteCar(int id)
        {
            var car = await _carRepository.GetByIdAsync(id);

            if (car == null)
            {
                ViewBag.ErrorMessage = $"Car with Id = {id} cannot be found";
                return(View("NotFound"));
            }
            else
            {
                var result = _carRepository.Delete(id);

                if (result != null)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    throw new NullReferenceException();
                }

                //return View("Index");
            }
        }
        public void Delete(Guid id)
        {
            var car = _carRepository.GetById(id);

            _carRepository.Delete(car);
            _memoryCache.Remove(_allCarsKey);
        }
        public async Task <IActionResult> DeleteMessage(int id, int userId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var messageFromRepo = await _repo.GetMessage(id);

            if (messageFromRepo.SenderId == userId)
            {
                messageFromRepo.SenderDeleted = true;
            }

            if (messageFromRepo.RecipientId == userId)
            {
                messageFromRepo.RecipientDeleted = true;
            }

            if (messageFromRepo.SenderDeleted && messageFromRepo.RecipientDeleted)
            {
                _repo.Delete(messageFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            else
            {
                throw new Exception("Eroare la stergerea mesajului");
            }
        }
Beispiel #8
0
        public ActionResult DeleteConfirmed(int id)
        {
            Car car = carsRepository.GetById((int)id);

            carsRepository.Delete(car);

            return(RedirectToAction("Index"));
        }
Beispiel #9
0
        public IActionResult Delete(int id)
        {
            var car = _carRepository.GetById(id);

            _carRepository.Delete(car);

            return(RedirectToAction("List"));
        }
        private void BtnDelete_Click(object sender, EventArgs e)
        {
            var currentId = int.Parse(InputId.Text);

            _carRepository.Delete(currentId);
            ClearForm();
            GetData();
        }
        public async Task <CarDTO> DeleteAsync(long Id)
        {
            Car result = await _carRepository.Delete(Id);

            var car = _mapper.Map <Car, CarDTO>(result);

            return(car);
        }
Beispiel #12
0
 public IResult Remove(Car car)
 {
     _carRepository.Delete(car);
     return(new SuccessResult()
     {
         Message = Messages.CarDeleted
     });
 }
        public ActionResult DeleteConfirmed(int id)
        {
            Car car = _carRepository.GetCar(id);

            _carRepository.Delete(id);
            _carRepository.Save();
            return(RedirectToAction("Index"));
        }
Beispiel #14
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _repo.GetUser(userId, true);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("Nu poti sterge poza de profil"));
            }

            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);

                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }

            if (photoFromRepo.PublicId == null)
            {
                _repo.Delete(photoFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Eroare la stergerea pozei."));
        }
        public async Task <IActionResult> DeleteAnnounce(Announce announce)
        {
            if (announce.UserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value) && User.FindFirst(ClaimTypes.Role).Value != "Admin")
            {
                return(Unauthorized());
            }

            _repo.Delete(announce);
            var carForDelete = await _repo.GetCar(announce.CarId);

            _repo.Delete(carForDelete);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            return(BadRequest("Stergerea a esuat!"));
        }
 public virtual async Task DeleteCar(Car car)
 {
     if (car == null)
     {
         throw new ArgumentNullException("deleteCar");
     }
     _carRepository.Delete(car);
     await _unitOfWork.SaveChangesAsync();
 }
            public async Task <IResult> Handle(DeleteCarCommand request, CancellationToken cancellationToken)
            {
                var carToDelete = _carRepository.Get(p => p.Id == request.Id);

                _carRepository.Delete(carToDelete);
                await _carRepository.SaveChangesAsync();

                return(new SuccessResult(Messages.Deleted));
            }
Beispiel #18
0
        private void BtnRemove_Click(object sender, EventArgs e)
        {
            var currentId = int.Parse(InputId.Text);
            var dbCar     = _carRepository.Cars.SingleOrDefault(c => c.Id == currentId);

            _carRepository.Delete(dbCar);
            ClearForm();
            GetData();
        }
Beispiel #19
0
        public ActionResult DeleteConfirmed(int id)

        {
            CarEntity carEntity = _carRepository.GetWhere(x => x.Id == id).FirstOrDefault();

            _carRepository.Delete(carEntity);

            return(RedirectToAction("Index"));
        }
Beispiel #20
0
        public JsonResult Delete(int id, int find = 0, string keyword = "", int pgnum = 1, int pgsize = 0)
        {
            o.Delete(id);
            string itemscount = o.GetItemMessage(find, keyword, pgnum, pgsize);

            return(Json(new Dictionary <string, object> {
                { "success", 1 }, { "itemscount", itemscount }
            }, JsonRequestBehavior.AllowGet));
        }
        public async Task <IActionResult> DeletePhoto(int userId, int carId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var carFromRepo = await _repo.GetCar(carId, true);

            if (carFromRepo.UserId != userId)
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo.IsMain)
            {
                return(BadRequest("You cannot delete your main photo"));
            }

            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);

                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }
            else
            {
                _repo.Delete(photoFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
        public IActionResult Delete(int carId)
        {
            Car car = repository.Delete(carId);

            if (car != null)
            {
                TempData["message"] = $"{car.Name} is succesfully deleted";
            }
            return(RedirectToAction("Index"));
        }
Beispiel #23
0
        public AddCarResponse Delete(int id)
        {
            var response = new AddCarResponse
            {
                Errors = new List <string>()
            };

            _carRepository.Delete(id);

            response.Success = true;
            return(response);
        }
        public ActionResult Delete(string carId)
        {
            var id  = Guid.Parse(carId);
            var car = _carRepository.Get(id);

            if (!car.IsNull())
            {
                _carRepository.Delete(car);
            }

            return(this.RedirectToAction <HomeController>(c => c.Index()).WithSuccess("Car deleted!"));
        }
Beispiel #25
0
        public ActionResult Delete(int id, Car car)
        {
            try
            {
                repository.Delete(id);

                return(RedirectToAction("List"));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #26
0
        public async Task <ActionResult <Car> > DeleteCar(Guid id)
        {
            var car = await _carRepository.GetById(id);

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

            await _carRepository.Delete(car.Id);

            return(car);
        }
Beispiel #27
0
        public async Task <ActionResult> Delete(int id)
        {
            try
            {
                await carRepository.Delete(id);

                return(Ok());
            }
            catch
            {
                return(BadRequest());
            }
        }
Beispiel #28
0
 public ActionResult Delete(int id, Car car)
 {
     try
     {
         _carRep.Delete(id);
         _carRep.Save();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Beispiel #29
0
        public async Task Execute(int id)
        {
            if (id == 0)
            {
                throw new CarNotFoundException("Carro não encontrado.");
            }
            var car = await this._repository.FindById(id);

            if (car == null)
            {
                throw new CarNotFoundException("Carro não encontrado.");
            }
            await _repository.Delete(car);
        }
Beispiel #30
0
        public async Task <bool> DeleteCar(Guid id)
        {
            try
            {
                var car = await GetCarById(id);

                _carRepository.Delete(car);
                await _carRepository.SaveAsync();

                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }