Ejemplo n.º 1
0
        public async Task CreateOffer(CreateOfferForm model, int currentUserId)
        {
            var deal = await _context.Deals.FirstOrDefaultAsync(x => x.Id == model.DealId);

            if (deal == null || deal.OwnerId == currentUserId ||
                deal.Offers.Any(x => x.OffererId == currentUserId) || model.OffererId != currentUserId)
            {
                throw new AccessViolationException("Wrong data to create new offer.");
            }

            _context.Offers.Add(Mapper.Map <Offer>(model));
            await _context.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> CreateOffer(CreateOfferForm model)
        {
            if (model.DealRate < model.InterestRate)
            {
                ModelState.AddModelError(nameof(model.InterestRate), "Вы превысили максимально допустимую процентную ставку.");
            }

            if (ModelState.IsValid)
            {
                await _offerService.CreateOffer(model, User.Identity.GetUserId <int>());

                return(RedirectToAction("Details", "Deal", new { id = model.DealId }));
            }

            return(View(model));
        }