Пример #1
0
        public async Task <OfferDto> CreateOffer(CreateOfferDto createOfferDto)
        {
            Offer offer = _mapper.Map <Offer>(createOfferDto);

            // Get and check company
            CompanyDto offerCompany = await _companyBusiness.GetFirstOrDefault <CompanyDto>(company => company.Id == createOfferDto.IdCompany) ?? throw new ConditionFailedException("Company was not found.");;

            // Get and check skills
            ICollection <SkillDto> offerSkills = await _skillBusiness.Get <SkillDto>(skill => createOfferDto.Skills.Contains(skill.Id));

            if (createOfferDto.Skills.Count != offerSkills.Count)
            {
                throw new ConditionFailedException("One or multiple skills do not exist.");
            }

            offer = await _repository.Add(offer);

            foreach (SkillDto skillDto in offerSkills)
            {
                offer.OfferSkill.Add(new OfferSkill {
                    Offer = offer.Id, Skill = skillDto.Id
                });
            }

            offer = await _repository.Update(offer);

            OfferDto mappedOffer = _mapper.Map <OfferDto>(offer);

            mappedOffer.Skills  = offerSkills;
            mappedOffer.Company = offerCompany;

            return(mappedOffer);
        }
Пример #2
0
        public async Task <IActionResult> CreateOffer([FromBody] CreateOfferDto request)
        {
            await bus.Send(new CreateOffer.Command
            {
                TaskId       = request.TaskId,
                OrderId      = new OrderId(request.OrderId),
                SelectedHero = new HeroId(request.SelectedHero)
            });

            return(Ok());
        }
Пример #3
0
 public ActionResult Create(CreateOfferDto offer)
 {
     try
     {
         offer.AdId   = offer.AdId;
         offer.UserId = GetUserId().Result;
         _createOfferCommand.Execute(offer);
         return(RedirectToAction("Index", "Home"));
     }
     catch (Exception e)
     {
         return(StatusCode(500, e.Message));
     }
 }
Пример #4
0
        public async Task <IActionResult> AddOffer([FromBody] CreateOfferDto offerDto)
        {
            var offer = _mapper.Map <Offer>(offerDto);
            await _unitOfWork.Offers.Add(offer);

            var success = _unitOfWork.Complete();

            if (success == 1)
            {
                return(CreatedAtAction(nameof(Get), new { id = offer.Id }, offer));
            }
            else
            {
                return(BadRequest());
            }
        }
Пример #5
0
        public void Execute(CreateOfferDto request)
        {
            if (_context.Offers.Any(x => x.UserId == request.UserId && x.AdId == request.AdId))
            {
                throw new EntityAlreadyExistsException("Offer");
            }

            _context.Offers
            .Add(new Offer()
            {
                AdId   = request.AdId,
                UserId = request.UserId,
                Amount = request.Amount
            });
            _context.SaveChanges();
        }
Пример #6
0
        public async Task <ActionResult> PostOffer(CreateOfferDto createOfferDto)
        {
            try
            {
                if (!IsCompany(createOfferDto.IdCompany))
                {
                    return(Unauthorized("You can not create this offer with this company."));
                }

                OfferDto offerDto = await _business.CreateOffer(createOfferDto);

                return(Created(offerDto.Id.ToString(), offerDto));
            }
            catch (ConditionFailedException exception)
            {
                return(BadRequest(exception.Message));
            }
        }
Пример #7
0
        public async Task <IActionResult> CreateAsync([FromBody] CreateOfferDto request)
        {
            var command = Mapper.Map <CreateOfferCommand>(request);

            return(Ok(await Mediator.Send(command)));
        }