Пример #1
0
        /// <summary>
        /// Добавляет предложение
        /// </summary>
        /// <returns></returns>
        public async Task <bool> AddOfferAsync(Guid userId, string currencyFromId, string currencyToId, decimal volume, decimal price, OfferType offerType)
        {
            if (volume == 0 || price == 0 || !await _currencyClient.CheckCurrencyPairAsync(currencyFromId, currencyToId))
            {
                return(false);
            }

            var currencyId = offerType == OfferType.Ask
                ? currencyFromId
                : currencyToId;

            if (!await _transactionClient.ReserveAsync(userId, currencyId, volume))
            {
                return(false);
            }

            try
            {
                var sameOffers = (await _offerRepository.GetList(userId))
                                 .Where(o => o.Price == price && o.CurrencyFromId == currencyFromId.ToUpper() &&
                                        o.CurrencyToId == currencyToId.ToUpper() && o.OfferType == offerType);

                var offer = new Offer
                {
                    UserId         = userId,
                    CreatedAt      = DateTime.UtcNow,
                    Volume         = volume + sameOffers.Sum(o => o.Volume),
                    CurrencyFromId = currencyFromId.ToUpper(),
                    CurrencyToId   = currencyToId.ToUpper(),
                    Price          = price,
                    OfferId        = Guid.NewGuid(),
                    OfferType      = offerType
                };

                _offerRepository.RemoveRange(sameOffers);
                _offerRepository.Add(offer);

                await _unitOfWork.SaveChangesAsync();

                var offers = (await _offerRepository.GetList(currencyToId.ToUpper(), currencyFromId.ToUpper(), MathOperations.RoudDivision(1, price)));

                //TODO Реализовать
                //await Matching(offer.Volume, price, userId, offers, currencyFromId, currencyToId);

                return(true);
            }
            catch (Exception e)
            {
                await _transactionClient.RemoveReserveAsync(userId, currencyFromId, volume);

                return(false);
            }
        }
Пример #2
0
        public Offer CreateOffer(string username, string model, int year, int mileage, string description, double price, string color, string fuel, string category, int seatsNb, int doorsNb, int displacement, string gearbox, string drive, bool damaged, bool abs, bool airbags, bool centrallock, bool aircond, DateTime starttime, DateTime endtime, string status, string make, string photouri)
        {
            var offer = new Offer()
            {
                Username     = username,
                Model        = model,
                Year         = year,
                Mileage      = mileage,
                Description  = description,
                Price        = price,
                Color        = color,
                Fuel         = fuel,
                Category     = category,
                SeatsNb      = seatsNb,
                DoorsNb      = doorsNb,
                Displacement = displacement,
                Gearbox      = gearbox,
                Drive        = drive,
                Damaged      = damaged,
                ABS          = abs,
                Airbags      = airbags,
                CentralLock  = centrallock,
                AirCond      = aircond,
                StartTime    = starttime,
                EndTime      = endtime,
                Status       = status,
                Make         = make,
                PhotoUri     = photouri
            };


            _offerRepository.Add(offer);
            _offerRepository.Commit();
            return(offer);
        }
Пример #3
0
        public Offer Create(Offer offer)
        {
            _repo.Add(offer);
            _repo.SaveChanges();

            return(offer);
        }
Пример #4
0
        public OfferDto AddOffer(OfferDto offerDto)
        {
            offerDto.ClientID = GetClientID(offerDto);

            Offer offer = Mapper.Map <OfferDto, Offer>(offerDto);

            offer = _offerRepository.Add(offer);

            //TODO: stored procedure that will take xml and process offer
            foreach (OfferNoteDto noteDto in offerDto.OfferNotes)
            {
                noteDto.OfferID = offer.ID;

                OfferNote note = Mapper.Map <OfferNoteDto, OfferNote>(noteDto);
                _offerNoteRepository.Add(note);
            }

            foreach (OfferSectionDto sectionDto in offerDto.OfferSections)
            {
                sectionDto.OfferID = offer.ID;

                OfferSection section = Mapper.Map <OfferSectionDto, OfferSection>(sectionDto);
                section = _offerSectionRepository.Add(section);

                foreach (OfferItemDto itemDto in sectionDto.OfferItems)
                {
                    itemDto.OfferSectionID = section.ID;

                    OfferItem item = Mapper.Map <OfferItemDto, OfferItem>(itemDto);
                    _offerItemRepository.Add(item);
                }
            }

            return(Mapper.Map <Offer, OfferDto>(offer));
        }
        public async Task <Offer> Handle(CreateOfferCommand request, CancellationToken cancellationToken)
        {
            var offer = new Offer(request.Description, request.OfferTypeId, request.EmployerId);

            _offerReposiyoty.Add(offer);

            return(await _offerReposiyoty.UnitOfWork.SaveEntitiesAsync(cancellationToken) ? offer : null);
        }
Пример #6
0
        public Offer Add(Offer offer)
        {
            var dbOffer        = Mapper.Map <DbOffer>(offer);
            var createdDbOffer = _offerRepository.Add(dbOffer);
            var createdOffer   = Mapper.Map <Offer>(createdDbOffer);

            return(createdOffer);
        }
Пример #7
0
        public OffersDto Add(OffersDto newOffer)
        {
            var offer      = mapper.Map <Offer>(newOffer);
            var addedOffer = offerRepository.Add(offer);

            unitOfWork.Commit();
            return(mapper.Map <OffersDto>(addedOffer));
        }
Пример #8
0
        public async Task <OfferModel> Create(OfferModel model)
        {
            model.ID = Guid.NewGuid();
            var data = await _offerRepo.Add(model);

            data = await this.UpdateOfferImage(data, model);

            return(data);
        }
Пример #9
0
        public async Task Seed()
        {
            var existing = await offerRepository.WithNumber("OFF001");

            if (existing == null)
            {
                offerRepository.Add(SampleOfferData.SampleOffer("OFF001"));
            }
        }
Пример #10
0
            public async Task <string> Handle(CreateOfferCommand request, CancellationToken cancellationToken)
            {
                var newOfferToAdd = new Offer(request.Name, request.PhotoUrl, request.StartDate, request.EndDate);

                _offerRepository.Add(newOfferToAdd);

                await _offerRepository.UnitOfWork.SaveEntitiesSeveralTransactionsAsync(cancellationToken);

                return(newOfferToAdd.Id.ToString());
            }
Пример #11
0
        public IActionResult Create([FromBody] Offer off)
        {
            if (off == null)
            {
                BadRequest();
            }

            // TODO ein paar Berechnungen bzgl. des Crowdshare und Prüfung auf Abschluss.
            Offers.Add(off);
            return(CreatedAtRoute("GetOffer", new { controller = "Offer", id = off.Id }, off));
        }
Пример #12
0
        public async Task <Offer> CreateOfferAsync(Offer offer, IFormFileCollection file)
        {
            var imagesIds = await _imageSaver.SaveImagesAsync(file);

            offer.Id           = Guid.NewGuid().ToString();
            offer.Images       = imagesIds;
            offer.State        = (int)StateOffer.NotConfirmed;
            offer.CreationDate = new DateTime();
            _offerRepository.Add(offer);
            return(offer);
        }
Пример #13
0
 public void Add(Offer offer)
 {
     try
     {
         _offerRepository.Add(offer);
         _offerRepository.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Пример #14
0
        public async Task CreateOffer_ShouldReturnOfferWithOverridenId()
        {
            // Arrange
            var oldId = "oldId";
            var offer = new Offer()
            {
                Id = oldId
            };

            _offerRepositoryMock.Add(Arg.Any <Offer>());

            _imageSaver.SaveImagesAsync(Arg.Any <IFormFileCollection>()).Returns(new List <string>());

            // Act
            var result = await _offerService.CreateOfferAsync(offer, null);

            // Assert
            result.Id.Should().NotBe(oldId);
        }
Пример #15
0
 public void CreateOffer(Offer Offer)
 {
     OfferRepository.Add(Offer);
 }
Пример #16
0
 public void AddOffer(Offer offer)
 {
     _offerRepository.Add(offer);
 }
Пример #17
0
 public void CreateOffer(Offer offer)
 {
     offersRepository.Add(offer);
 }