Ejemplo n.º 1
0
        public void GetByID_ValidCurrencyID_ReturnsCurrency()
        {
            // Arrange

            // Act
            var currency = _currencyService.GetByID("NGN");

            // Assert
            Assert.IsInstanceOfType(currency, typeof(Currency));
            Assert.AreEqual("NGN", currency.CurrencyID);
        }
Ejemplo n.º 2
0
        public ActionResult AddExchangeOffer(AddExchangeOfferVM model)
        {
            Auto targetAuto = AutoService.GetPublishedByID(model.TargetAutoID);

            if (targetAuto == null)
            {
                return(HttpNotFound());
            }

            User currentUser = UserService.GetUserByEmail(User.Identity.Name);
            AutoExchangeDetailsVM exchangeDetailsVM = null;

            try
            {
                AutoExchange newExchange = new AutoExchange()
                {
                    OfferedAutoID      = model.OfferedAutoID,
                    TargetAutoID       = model.TargetAutoID,
                    DateCreated        = DateTime.Now,
                    CurrencyID         = model.CurrencyID,
                    DiffPrice          = model.DiffPrice,
                    DiffPriceDirection = model.DiffPriceDirection
                };
                AutoExchangeService.Create(newExchange);

                Currency currency = CurrencyService.GetByID(newExchange.CurrencyID);

                Auto offeredAuto = AutoService.GetByID(model.OfferedAutoID);
                exchangeDetailsVM = targetAuto.AutoExchangesIncome.FirstOrDefault(ex => ex.ID == newExchange.ID);
                if (exchangeDetailsVM != null)
                {
                    exchangeDetailsVM.Currency = currency.Symbol;
                    exchangeDetailsVM.DeleteButtonIsAvailable = (currentUser != null && (currentUser.ID == offeredAuto.UserID || currentUser.ID == offeredAuto.UserID));
                }
            }
            catch (Exception ex)
            {
                ViewBag.errorMsg = "Error: " + ex.Message;
            }

            return(PartialView("_ExchangeOffer", exchangeDetailsVM));
        }
Ejemplo n.º 3
0
        public ActionResult GetAutosFromElastic(int draw, int start, int length, ExtendedSearchVM modelVM, bool forHomePage = false, bool related = false, bool forErrorPage = false)
        {
            int                   recordsFiltered = 0;
            string                error           = "";
            List <dynamic>        autos           = new List <dynamic>();
            List <dynamic>        auctions        = new List <dynamic>();
            List <List <string> > data            = new List <List <string> >();

            if (modelVM == null)
            {
                recordsFiltered = 0;
            }
            else
            {
                bool viewingOwnAutos = false;

                if (modelVM.UserID == null)
                {
                    modelVM.StatusID = 2;
                }
                else
                {
                    if (User.Identity.IsAuthenticated)
                    {
                        User user = UserService.GetUserByEmail(User.Identity.Name);
                        if (modelVM.UserID == user.ID)
                        {
                            viewingOwnAutos = true;
                        }
                        else
                        {
                            modelVM.StatusID = 2;
                        }
                    }
                    else
                    {
                        modelVM.StatusID = 2;
                    }
                }
                //*******************************
                //modelVM.UserID = 16;
                //modelVM.StatusID = null; //should be commented
                //*******************************

                List <AutoShortInfoVM>    autoModelsVM    = new List <AutoShortInfoVM>();
                List <AuctionShortInfoVM> auctionModelsVM = new List <AuctionShortInfoVM>();

                if (modelVM.Type == "auction")
                {
                    auctions = SearchAutoService.ExtendedSearch(start, length, modelVM, out recordsFiltered, out error);
                }
                else
                {
                    autos = SearchAutoService.ExtendedSearch(start, length, modelVM, out recordsFiltered, out error);
                }

                string usdSymbol = CurrencyService.GetByID(1).Symbol;
                string uahSymbol = CurrencyService.GetByID(2).Symbol;

                if (modelVM.Type == "auction")
                {
                    foreach (var item in auctions)
                    {
                        AuctionShortInfoVM auctionShortInfoVM = CreateAuctionShortInfoVM(item, usdSymbol, uahSymbol);
                        auctionModelsVM.Add(auctionShortInfoVM);
                    }
                }
                else
                {
                    foreach (var item in autos)
                    {
                        AutoShortInfoVM autoShortInfoVM = CreateAutoShortInfoVM(item, usdSymbol, uahSymbol);
                        autoModelsVM.Add(autoShortInfoVM);
                    }
                }

                string html = "";
                if (forHomePage)
                {
                    if (modelVM.Type == "auction")
                    {
                        html = ViewRenderer.RenderPartialView("~/Views/AuctionCardPartial/_AuctionCardHomeMultiple.cshtml", auctionModelsVM, ControllerContext);
                    }
                    else
                    {
                        html = ViewRenderer.RenderPartialView("~/Views/AutoCardPartial/_AutoCardHomeMultiple.cshtml", autoModelsVM, ControllerContext);
                    }
                }
                else if (forErrorPage)
                {
                    html = ViewRenderer.RenderPartialView("~/Views/AutoCardPartial/_AutoCardError.cshtml", autoModelsVM, ControllerContext);
                }
                else if (related)
                {
                    if (modelVM.Type == "auction")
                    {
                        html = ViewRenderer.RenderPartialView("~/Views/AuctionCardPartial/_AuctionCardRelatedMultiple.cshtml", auctionModelsVM, ControllerContext);
                    }
                    else
                    {
                        html = ViewRenderer.RenderPartialView("~/Views/AutoCardPartial/_AutoCardRelatedMultiple.cshtml", autoModelsVM, ControllerContext);
                    }
                }
                else
                {
                    if (viewingOwnAutos)
                    {
                        if (modelVM.Type == "auction")
                        {
                            html = ViewRenderer.RenderPartialView("~/Views/AuctionCardPartial/_AuctionCardInCabinetMultiple.cshtml", auctionModelsVM, ControllerContext);
                        }
                        else
                        {
                            html = ViewRenderer.RenderPartialView("~/Views/AutoCardPartial/_AutoCardInCabinetMultiple.cshtml", autoModelsVM, ControllerContext);
                        }
                    }
                    else
                    {
                        if (modelVM.Type == "auction")
                        {
                            html = ViewRenderer.RenderPartialView("~/Views/AuctionCardPartial/_AuctionCardMultiple.cshtml", auctionModelsVM, ControllerContext);
                        }
                        else
                        {
                            html = ViewRenderer.RenderPartialView("~/Views/AutoCardPartial/_AutoCardMultiple.cshtml", autoModelsVM, ControllerContext);
                        }
                    }
                }

                if (html != "")
                {
                    data.Add(new List <string>()
                    {
                        html
                    });
                }
            }

            return(Json(new { draw = draw, recordsFiltered = recordsFiltered, data = data, error = error } /*, JsonRequestBehavior.AllowGet*/));
        }