public ValidationResult ValidateAddOfferDto(AddOfferDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException(ArgumentExceptionResources.AddOfferDtoNotFound);
            }
            var validationResult = new ValidationResult("Добавление предложения");

            var application = _unitOfWork.Repository <IApplicationRepository>().Get(dto.ApplicationId);

            if (application == null)
            {
                validationResult.AddError(ValidationErrorResources.ApplicationNotFound);
            }

            if (dto.Price == default(float))
            {
                validationResult.AddError(ValidationErrorResources.OfferPriceNotFound);
            }

            if (string.IsNullOrEmpty(dto.Content))
            {
                validationResult.AddError(ValidationErrorResources.OfferContentNotFound);
            }

            return(validationResult);
        }
 public IActionResult TradeOffered(AddOfferDto newOffer)
 {
     if (_repo.AddOffer(newOffer))
     {
         return(Ok());
     }
     else
     {
         return(BadRequest());
     }
 }
Example #3
0
 public bool AddOffer(AddOfferDto newOffer)
 {
     using (var db = new SqlConnection(_connectionString))
     {
         var sql = @"INSERT INTO [Offer]
                     ([Offered]
                     ,[Requested]
                     ,[Message])
                 VALUES
                     (@offered
                     ,@requested
                     ,@message)";
         return(db.Execute(sql, newOffer) == 1);
     }
 }
        public void AddOffer(AddOfferDto dto, string currentUserId)
        {
            UserManager.IsUserInCarServiceRole(currentUserId);
            var user = UserManager.CheckAndGet(currentUserId);

            var validationResult = _validationManager.ValidateAddOfferDto(dto);

            if (validationResult.HasErrors)
            {
                throw new BusinessFaultException(validationResult.GetErrors());
            }

            var application = UnitOfWork.Repository <IApplicationRepository>().Get(dto.ApplicationId);

            // Заявка не находится в состоянии поиска
            if (application.State != ApplicationState.InSearch)
            {
                throw new BusinessFaultException(BusinessLogicExceptionResources.ApplicationIncorrectState);
            }

            if (application.Offers == null)
            {
                application.Offers = new List <ApplicationOffer>();
            }

            // От автосервиса уже предложение подано
            if (application.Offers.Any(of => of.Service.Id == user.CarService.Id && !of.IsDeleted))
            {
                throw new BusinessFaultException(BusinessLogicExceptionResources.ApplicationOfferAlreadyContains);
            }

            var offer = Mapper.Map <ApplicationOffer>(dto);

            offer.Application = application;
            offer.Service     = user.CarService;

            application.Offers.Add(offer);
            UnitOfWork.SaveChanges();
        }
 public IHttpActionResult AddOffer(AddOfferDto dto)
 {
     return(CallBusinessLogicAction(() => _manager.AddOffer(dto, User.Identity.GetUserId())));
 }