Exemplo n.º 1
0
        public ActionResult RequestToRent(int id, decimal Price = 0)
        {
            var userMoney = _rentService.GetUserByLogin(User.Identity.Name).SumMoney;

            if (userMoney < Price)
            {
                return(HttpNotFound());
            }
            if (!_rentService.CheckedIsTakenProductByProductId(id))
            {
                return(HttpNotFound());
            }
            //Если нельзя снять то выдаем ошибку, а не 404
            if (!_rentService.WriteOffMoneyFromUserByLogin(Price, User.Identity.Name))
            {
                return(HttpNotFound());
            }

            var takenProduct = new TakenProduct
            {
                ProductId = id,
                UserId    = _rentService.GetUserByLogin(User.Identity.Name).Id,
                Cost      = Price,
            };

            _rentService.CreateTakenProduct(takenProduct);
            return(RedirectToAction("RequestedAd"));
        }
Exemplo n.º 2
0
 public bool CreateTakenProduct(TakenProduct takenProduct)
 {
     using (var db = new RentContext())
     {
         db.TakenProducts.AddOrUpdate(takenProduct);
         db.SaveChanges();
         return(true);
     }
 }