Esempio n. 1
0
        public async Task <GetOfferBasicInfoResponse> GetOfferBasicInfo(
            GetOfferBasicInfoRequest request, CallContext context = default)
        {
            var offer = await _offerRepository.GetByIdAsync(request.OfferId);

            if (offer == null)
            {
                return(new GetOfferBasicInfoResponse());
            }

            var offerDto = new OfferDto
            {
                Id             = offer.Id,
                Name           = offer.Name,
                OwnerId        = offer.OwnerId,
                AvailableStock = offer.AvailableStock,
                Price          = offer.Price,
                Images         = offer.Images?.Select(img => new ImageDto
                {
                    Id     = img.Id,
                    Uri    = img.Uri,
                    IsMain = img.IsMain
                }) ?? new List <ImageDto>(),
                IsActive = offer.IsActive
            };

            return(new GetOfferBasicInfoResponse {
                Offer = offerDto
            });
        }
Esempio n. 2
0
        public async Task <IActionResult> CancelOffer([FromBody] OfferDto offerDto)
        {
            try
            {
                var produtOffers = await _blockChainService.CancelOffer(offerDto.UserId,
                                                                        offerDto.ProductName,
                                                                        offerDto.PrivateKey,
                                                                        offerDto.ProductOffer.AskAssetName,
                                                                        offerDto.ProductOffer.AskQuantity,
                                                                        offerDto.ProductOffer.OfferAssetName,
                                                                        offerDto.ProductOffer.OfferQuantity,
                                                                        offerDto.ProductOffer.HexBlob,
                                                                        offerDto.ProductOffer.PxCoin,
                                                                        offerDto.ProductOffer.TxId);

                return(Ok(produtOffers));
            }
            catch (LucidOcean.MultiChain.Exceptions.JsonRpcException ex)
            {
                Logger.LogException(Log, ex, MethodBase.GetCurrentMethod());
                var error = new
                {
                    ErrorCode    = ex.Error.Code,
                    ErrorMessage = ex.Error.Message
                };
                return(BadRequest(error));
            }
            catch (Exception ex)
            {
                Logger.LogException(Log, ex, MethodBase.GetCurrentMethod());
                return(new StatusCodeResult(503));
            }
        }
Esempio n. 3
0
        public IActionResult AddOffer([FromBody] OfferDto offerDto)
        {
            itemsService.AddOffer(offerDto,
                                  HttpContext.User.Claims.Where(c => c.Type == ClaimTypes.Name).Select(x => int.Parse(x.Value)).FirstOrDefault());

            return(Ok());
        }
Esempio n. 4
0
        private static MailMessage GenerateRescindedOfferEmail(string rioUrl, OfferDto offer,
                                                               TradeDto currentTrade,
                                                               PostingDto posting, SitkaSmtpClientService smtpClient)
        {
            var offerAction = currentTrade.CreateAccount.AccountID == offer.CreateAccount.AccountID
                ? posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy ? "sell" : "buy"
                : posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy ? "buy" : "sell";

            var toAccount   = offer.CreateAccount.AccountID == posting.CreateAccount.AccountID ? currentTrade.CreateAccount : posting.CreateAccount;
            var fromAccount = offer.CreateAccount.AccountID == posting.CreateAccount.AccountID
                ? posting.CreateAccount
                : currentTrade.CreateAccount;

            var properPreposition = offerAction == "sell" ? "to" : "from";
            var messageBody       =
                $@"
Hello,
<br /><br />
An offer to {offerAction} water {properPreposition} Account #{fromAccount.AccountNumber} ({fromAccount.AccountName}) was rescinded by the other party. You can see details of your transactions in the Water Accounting Platform Landowner Dashboard. 
<br /><br />
<a href=""{rioUrl}/landowner-dashboard/{toAccount.AccountNumber}"">View Landowner Dashboard</a>
{smtpClient.GetDefaultEmailSignature()}";
            var mailMessage = new MailMessage
            {
                Subject = $"Trade {currentTrade.TradeNumber} Rescinded",
                Body    = messageBody
            };

            foreach (var user in toAccount.Users)
            {
                mailMessage.To.Add(new MailAddress(user.Email, user.FullName));
            }
            return(mailMessage);
        }
Esempio n. 5
0
        private static MailMessage GeneratePendingOfferEmail(string rioUrl, TradeDto currentTrade,
                                                             OfferDto offer, PostingDto posting, SitkaSmtpClientService smtpClient)
        {
            var offerAction = currentTrade.CreateAccount.AccountID == offer.CreateAccount.AccountID
                ? posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy ? "sell" : "buy"
                : posting.PostingType.PostingTypeID == (int)PostingTypeEnum.OfferToBuy ? "buy" : "sell";
            var toAccount   = offer.CreateAccount.AccountID == posting.CreateAccount.AccountID ? currentTrade.CreateAccount : posting.CreateAccount;
            var fromAccount = offer.CreateAccount.AccountID == posting.CreateAccount.AccountID
                ? posting.CreateAccount
                : currentTrade.CreateAccount;

            var properPreposition = offerAction == "sell" ? "to" : "from";
            var messageBody       =
                $@"
Hello,
<br /><br />
An offer to {offerAction} water {properPreposition} Account #{fromAccount.AccountNumber} ({fromAccount.AccountName}) has been presented for your review. 
<br /><br />
<a href=""{rioUrl}/trades/{currentTrade.TradeNumber}"">Respond to this offer</a>
{smtpClient.GetDefaultEmailSignature()}";
            var mailMessage = new MailMessage
            {
                Subject = "New offer to review",
                Body    = messageBody
            };

            foreach (var user in toAccount.Users)
            {
                mailMessage.To.Add(new MailAddress(user.Email, user.FullName));
            }
            return(mailMessage);
        }
Esempio n. 6
0
        internal async Task <ProposalDto> PostOffer(string authToken, OfferDto offer)
        {
            var hasBeenAccepted = false;

            var fullDb = await CacheService.GetFullDb();

            var proposal = fullDb.First(p => p.ProposalId == offer.ProposalId);

            if (proposal.Status == Proposed && IsEqualOrBetter(proposal, offer))
            {
                proposal.Status = Accepted;
                hasBeenAccepted = true;
            }

            offer.Selected     = false;
            offer.CreationTime = DateTime.UtcNow;

            proposal.Offers.Add(offer);

            await CacheService.UpdataDb(fullDb);

            if (hasBeenAccepted && useWorkBench)
            {
                await _workBenchService.RecordAcceptance(authToken, proposal);
            }

            return(proposal);
        }
        public async Task <Result> Update(OfferDto offer)
        {
            var result = new Result
            {
                IsSuccess = true,
                EntityId  = offer.Id ?? Guid.Empty
            };

            try
            {
                _unitOfWork.Offers.Update(_mapper.Map <Offer>(offer));
                await _unitOfWork.SaveAsync();
            }
            catch (Exception exc)
            {
                result = new Result
                {
                    IsSuccess = false,
                    Error     = exc.Message,
                    EntityId  = Guid.Empty
                };
            }

            return(result);
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        public async Task <OfferDto> GetOffer(ulong offerId)
        {
            Offer offer = await _repository.GetAll().Include(o => o.OfferSkill).Where(o => o.Id == offerId).FirstOrDefaultAsync();

            if (offer == null)
            {
                return(null);
            }

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

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

            // Get and check skills
            ICollection <SkillDto> offerSkills = await _skillBusiness.Get <SkillDto>(skill => offer.OfferSkill.Select(os => os.Skill).Contains(skill.Id));

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

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

            return(mappedOffer);
        }
 public ChangePimpStatusBodyBuilder(EmployeeDto employee, ContragentDto contragent, OfferDto offer, string status)
 {
     _employee   = employee;
     _contragent = contragent;
     _offer      = offer;
     _status     = status;
 }
Esempio n. 11
0
        /// <summary>
        /// Method used for calculating the offer that will be served to the client
        /// </summary>
        /// <param name="offer">The body payload containing the chosen CityId and the chosen services</param>
        /// <returns>The presentation model containing the calculated offer details</returns>
        public async Task <OfferDto> CalculateOfferAsync(NewOfferDto offer)
        {
            if (offer == null)
            {
                throw new ArgumentNullException("IOffer model is null.");
            }

            if (!offer.Alternatives.Any())
            {
                throw new Exception("Services not set.");
            }

            try
            {
                var city = await _citiesService.GetCityByIdAsync(offer.CityId);

                var response = new OfferDto()
                {
                    City       = city.Name,
                    OfferItems = await SetOfferItemsAsync(offer.Alternatives, offer.MainServiceAmount),
                    Currency   = city.Currency
                };

                return(response);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 12
0
        private static void SetMostRecentOfferOfType(OfferDto mostRecentOffer, PostingDto mostRecentPosting,
                                                     MarketMetricsDto marketMetricsDto, Expression <Func <MarketMetricsDto, int?> > quantityFunc, Expression <Func <MarketMetricsDto, decimal?> > priceFunc)
        {
            var quantityExpression = (MemberExpression)quantityFunc.Body;
            var quantityProperty   = (PropertyInfo)quantityExpression.Member;
            var priceExpression    = (MemberExpression)priceFunc.Body;
            var priceProperty      = (PropertyInfo)priceExpression.Member;

            if (mostRecentOffer == null && mostRecentPosting == null)
            {
                quantityProperty.SetValue(marketMetricsDto, null);
                priceProperty.SetValue(marketMetricsDto, null);
            }
            else
            {
                var mostRecentOfferDate   = mostRecentOffer?.OfferDate;
                var mostRecentPostingDate = mostRecentPosting?.PostingDate;
                if (mostRecentPostingDate != null && mostRecentPostingDate > mostRecentOfferDate)
                {
                    quantityProperty.SetValue(marketMetricsDto, mostRecentPosting.Quantity);
                    priceProperty.SetValue(marketMetricsDto, mostRecentPosting.Price);
                }
                else
                {
                    quantityProperty.SetValue(marketMetricsDto, mostRecentOffer?.Quantity);
                    priceProperty.SetValue(marketMetricsDto, mostRecentOffer?.Price);
                }
            }
        }
Esempio n. 13
0
        public void UpdateOffer(OfferDto offerDto)
        {
            offerDto.ClientID = GetClientID(offerDto);

            Offer offer = _offerRepository.Find(offerDto.ID);

            _offerRepository.Update(Mapper.Map(offerDto, offer));

            //TODO: stored procedure that will take xml and process offer
            foreach (OfferNoteDto noteDto in offerDto.OfferNotes)
            {
                OfferNote note = _offerNoteRepository.Find(noteDto.ID.Value);
                _offerNoteRepository.Update(Mapper.Map(noteDto, note));
            }

            foreach (OfferSectionDto sectionDto in offerDto.OfferSections)
            {
                OfferSection section = _offerSectionRepository.Find(sectionDto.ID.Value);
                _offerSectionRepository.Update(Mapper.Map(sectionDto, section));

                foreach (OfferItemDto itemDto in sectionDto.OfferItems)
                {
                    OfferItem item = _offerItemRepository.Find(itemDto.ID.Value);
                    _offerItemRepository.Add(Mapper.Map(itemDto, item));
                }
            }
        }
Esempio n. 14
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));
        }
Esempio n. 15
0
        public async Task <ActionResult> CreateOffer(OfferDto offer)
        {
            await _posAuthLoader.AssertResourceAccessAsync(User, offer.PointOfSaleId, IsAuthorizedUserPolicy.Instance);

            var cmd = new CreateOffer(Guid.NewGuid(), offer.PointOfSaleId, offer.ProductId, offer.RecommendedPrice, offer.StockItemId, offer.ValidSince, offer.ValidUntil);

            return(await SendAndHandleIdentifierResultCommand(cmd, nameof(GetOffer)));
        }
Esempio n. 16
0
        public OfferDto EditOffer(OfferDto OfferDto, int userId, int tenantId, List <MemoryStream> files, string path, int imageCounter)
        {
            var OfferObj = _OfferService.Query(x => x.OfferId == OfferDto.OfferId && x.TenantId == tenantId).Select().FirstOrDefault();

            if (OfferObj == null)
            {
                throw new NotFoundException(ErrorCodes.ProductNotFound);
            }
            //  ValidateOffer(OfferDto, tenantId);
            foreach (var OfferName in OfferDto.TitleDictionary)
            {
                var OfferTranslation = OfferObj.OfferTranslations.FirstOrDefault(x => x.Language.ToLower() == OfferName.Key.ToLower() &&
                                                                                 x.OfferId == OfferDto.OfferId);
                if (OfferTranslation == null)
                {
                    OfferObj.OfferTranslations.Add(new OfferTranslation
                    {
                        Title       = OfferName.Value,
                        Description = OfferDto.DescriptionDictionary[OfferName.Key],
                        Language    = OfferName.Key
                    });
                }
                else
                {
                    OfferTranslation.Title       = OfferName.Value;
                    OfferTranslation.Description = OfferDto.DescriptionDictionary[OfferName.Key];
                }
            }

            OfferObj.CityId               = OfferDto.CityId;
            OfferObj.TypeId               = OfferDto.TypeId;
            OfferObj.HotelId              = OfferDto.HotelId;
            OfferObj.HotelTitle           = OfferDto.HotelTitle;
            OfferObj.DaysCount            = OfferDto.DaysCount;
            OfferObj.NigthsCount          = OfferDto.NigthsCount;
            OfferObj.Star                 = OfferDto.Star;
            OfferObj.PriceBefore          = OfferDto.PriceBefore;
            OfferObj.Price                = OfferDto.Price;
            OfferObj.LastModificationTime = Strings.CurrentDateTime;
            OfferObj.LastModifierUserId   = userId;
            OfferObj.IsDeleted            = OfferDto.IsDeleted;
            OfferObj.CurrencyId           = OfferDto.CurrencyId;

            OfferObj.DateFrom = OfferDto.DateFrom;
            OfferObj.DateTo   = OfferDto.DateTo;

            _OfferService.Update(OfferObj);
            SaveChanges();
            var imageId = 1;// imageCounter + 1;

            foreach (var memoryStream in files)
            {
                _manageStorage.UploadImage(path + "\\" + "Offer-" + OfferObj.OfferId, memoryStream, imageId.ToString());
                imageId++;
            }
            return(OfferDto);
        }
Esempio n. 17
0
        public async Task <IActionResult> Get(int id)
        {
            OfferDto result = await Mediator.Send(new GetByIdQuery <int, OfferDto>(id));

            if (result == null)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
Esempio n. 18
0
        public OfferDto Get(int id)
        {
            //db.Configuration.ProxyCreationEnabled = false;
            var getFirstVersion = db.Offers.Find(id);
            //var get = db.Offers.Include(i=>i.Files).AsNoTracking().Where(f => f.Id == id).First();

            OfferDto value = Mapper.Map <OfferDto>(getFirstVersion);

            return(value);
        }
Esempio n. 19
0
        public async Task Handle(OfferStockSet message)
        {
            ProductDto prod = _productRepository.GetById(message.Id);

            OfferDto offerDto = prod.Offers.Where(o => o.Id == message.OfferId).FirstOrDefault();

            offerDto.Stock = message.Stock;
            prod.Version   = message.Version;

            _productRepository.Update(prod);
        }
Esempio n. 20
0
 public static Offer MapOfferDtoToEntity(OfferDto offerDto)
 {
     return(new Offer()
     {
         Id = offerDto.Id,
         Value = offerDto.Value,
         Created = offerDto.Created,
         BuyerId = offerDto.Buyer.UserId,
         //PropertyId = offerDto.PropertyId
     });
 }
Esempio n. 21
0
        public async Task Handle(OfferHidden message)
        {
            ProductDto prod = _productRepository.GetById(message.Id);

            OfferDto offer = prod.Offers.Where(o => o.Id == message.OfferId).FirstOrDefault();

            offer.IsVisible = false;
            prod.Version    = message.Version;

            _productRepository.Update(prod);
        }
Esempio n. 22
0
        private static string SerializeObjectToXml(OfferDto offer)
        {
            Stream stream = new MemoryStream();

            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(OfferDto));
            x.Serialize(stream, offer);
            var outputString = stream.ToString();

            stream.Close();
            return(outputString);
        }
Esempio n. 23
0
 public static OfferViewModel Map(OfferDto offer)
 {
     return(new OfferViewModel
     {
         AirlineName = offer.AirlineName,
         CreationTime = offer.CreationTime,
         DepartureDate = offer.OutboundDate,
         ReturnDate = offer.InboundDate,
         Price = offer.Price,
         Selected = offer.Selected
     });
 }
Esempio n. 24
0
        public ActionResult Edit(OfferDto offerDto)
        {
            bool isOk = TryUpdateModel(offerDto);

            if (isOk && ModelState.IsValid)
            {
                _offerService.UpdateOffer(offerDto);

                return(RedirectToAction("Index"));
            }
            return(View(offerDto));
        }
Esempio n. 25
0
        public async Task <OfferDto> UpdateOffer(ulong offerId, string companyId, UpdateOfferDto updateOfferDto)
        {
            Offer offer = await _repository.GetAll().Include(o => o.OfferSkill).Where(o => o.Id == offerId).FirstOrDefaultAsync();

            if (offer == null)
            {
                return(null);
            }

            if (offer.IdCompany.ToString() != companyId)
            {
                throw new AuthenticationFailedException("You are not authorized to update this offer.");
            }

            _mapper.Map(updateOfferDto, offer);

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

            // Get and check skills
            ICollection <SkillDto> offerSkills = null;

            if (updateOfferDto.Skills != null)
            {
                offer.OfferSkill.Clear();
                offerSkills = await _skillBusiness.Get <SkillDto>(skill => updateOfferDto.Skills.Contains(skill.Id));

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

                foreach (SkillDto skillDto in offerSkills)
                {
                    offer.OfferSkill.Add(new OfferSkill {
                        Offer = offer.Id, Skill = skillDto.Id
                    });
                }
            }
            else
            {
                offerSkills = await _skillBusiness.Get <SkillDto>(skill => offer.OfferSkill.Select(os => os.Skill).Contains(skill.Id));
            }

            offer = await _repository.Update(offer);

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

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

            return(mappedOffer);
        }
Esempio n. 26
0
        public async Task PostOffer(OfferDto offer)
        {
            var offerSerialized = JsonConvert.SerializeObject(offer);

            var buffer      = Encoding.UTF8.GetBytes(offerSerialized);
            var byteContent = new ByteArrayContent(buffer);

            byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            byteContent.Headers.Add("X-Authorization", _configurationProvider.AuthorizationKey);

            await _httpClient.PostAsync(BmtPostOffersApiUrl, byteContent).ConfigureAwait(false);
        }
Esempio n. 27
0
        public void GetOffer_ConstructsQuery_ReturnsResultOfDispatch()
        {
            var offerId  = TestIds.A;
            var offerDto = new OfferDto();

            _dispatcherMock.Setup(d => d.QueryAsync(It.Is <GetOffer>(q => q.Id == offerId))).ReturnsAsync(offerDto).Verifiable();

            var actionResult = _controller.GetOffer(offerId).GetAwaiter().GetResult();

            Assert.AreEqual(offerDto, actionResult.Value);
            _dispatcherMock.Verify();
        }
Esempio n. 28
0
        public async Task <IHttpActionResult> PostOffer(OfferDto offerDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            offerDto.Id      = Guid.NewGuid();
            offerDto.Created = DateTime.UtcNow;
            await this.offersRepository.CreateOffer(offerDto.PropertyId, Mapper.MapOfferDtoToEntity(offerDto));

            return(CreatedAtRoute("DefaultApi", new { id = offerDto.Id }, offerDto));
        }
 private void PutOfferDataIntoControls(OfferDto offer)
 {
     currentOffer                    = Offer.CreateOffer();
     currentOffer.OfferId            = offer.OfferId;
     currentOffer.PublishDate        = DateTime.Parse(offer.PublishDate);
     currentOffer.Discount           = offer.Discount;
     currentOffer.Description        = offer.Description;
     currentOffer.Details            = offer.Details;
     PublishDateTextBox.Text         = currentOffer.PublishDate.ToShortDateString();
     DescriptionTextBox.Text         = currentOffer.Description;
     OfferTypeComboBox.SelectedIndex = currentOffer.OfferType - 1;
     DiscountNumericUpDown.Value     = decimal.Parse(currentOffer.Discount.ToString());
 }
Esempio n. 30
0
        public void AddOffer(OfferDto offerDto, int userId)
        {
            Offer offer = new Offer
            {
                CreateTime   = DateTime.UtcNow,
                HaveItemsIds = offerDto.HaveItemsIds,
                WantItemsIds = offerDto.WantItemsIds,
                UserId       = userId
            };

            dataContext.Offers.Add(offer);
            dataContext.SaveChanges();
        }