Example #1
0
        // GET: Auto
        public ActionResult Index()
        {
            breadcrumbs.Add("#", Resource.Advertisements);
            ViewBag.breadcrumbs = breadcrumbs;

            ExtendedSearchVM modelVM = new ExtendedSearchVM()
            {
                StatusID = 2
            };

            return(View("~/Views/SearchAuto/SearchResult.cshtml", modelVM));
        }
Example #2
0
        public ActionResult Index(int statusID = 0, string error = null)
        {
            if (statusID == 0)
            {
                statusID = 2;
            }
            User        user   = _userService.GetUserByEmail(User.Identity.Name);
            UserShortVM userVM = user;

            ViewBag.userVM = userVM;

            ViewBag.statuses         = _autoStatusService.GetAllAsSelectList(statusID);
            ViewBag.selectedStatusID = statusID;

            if (error != null)
            {
                ViewBag.error = error;
            }

            ViewBag.userID = user.ID;

            //breadcrumbs.Add("#", Resource.MyAdvertisements);
            breadcrumbs.Add("#", Resource.MyCabinet);
            ViewBag.breadcrumbs = breadcrumbs;
            ViewBag.activeTab   = "MyAutos";

            ExtendedSearchVM searchVM = new ExtendedSearchVM()
            {
                UserID = user.ID
            };

            if (statusID > 0)
            {
                searchVM.StatusID = statusID;
            }

            ViewBag.auctionSearchVM = new ExtendedSearchVM()
            {
                UserID   = user.ID,
                StatusID = 1,
                Type     = "auction"
            };

            ViewBag.auctionStatuses = AuctionStatusService.GetAllAsSelectList();

            return(View(searchVM));
        }
Example #3
0
        public ActionResult SearchResult(ExtendedSearchVM modelVM)
        {
            ViewBag.autosCountAddedToday = AutoStatisticsService.GetAutosCountAddedToday();

            if (modelVM.YearOfIssueFrom != null && modelVM.YearOfIssueFrom > 0 &&
                (modelVM.YearOfIssueTo == null || modelVM.YearOfIssueTo == 0))
            {
                int arrLength = DateTime.Now.Year - modelVM.YearOfIssueFrom.Value + 1;
                if (arrLength > 0)
                {
                    modelVM.YearOfIssue = new int[arrLength];
                    for (int i = modelVM.YearOfIssueFrom.Value, j = 0; i <= DateTime.Now.Year; i++, j++)
                    {
                        modelVM.YearOfIssue[j] = i;
                    }
                }
            }
            else if (modelVM.YearOfIssueTo != null && modelVM.YearOfIssueTo > 0 &&
                     (modelVM.YearOfIssueFrom == null || modelVM.YearOfIssueFrom == 0))
            {
                int arrLength = modelVM.YearOfIssueTo.Value - 1950 + 1;
                if (arrLength > 0)
                {
                    modelVM.YearOfIssue = new int[arrLength];
                    for (int i = modelVM.YearOfIssueTo.Value, j = 0; i >= 1950; i--, j++)
                    {
                        modelVM.YearOfIssue[j] = i;
                    }
                }
            }
            else if (modelVM.YearOfIssueTo != null && modelVM.YearOfIssueTo > 0 &&
                     modelVM.YearOfIssueFrom != null && modelVM.YearOfIssueFrom > 0)
            {
                int arrLength = modelVM.YearOfIssueTo.Value - modelVM.YearOfIssueFrom.Value + 1;
                if (arrLength > 0)
                {
                    modelVM.YearOfIssue = new int[arrLength];
                    for (int i = modelVM.YearOfIssueFrom.Value, j = 0; i <= modelVM.YearOfIssueTo.Value; i++, j++)
                    {
                        modelVM.YearOfIssue[j] = i;
                    }
                }
            }

            return(View(modelVM));
        }
Example #4
0
        // GET: Auction
        public ActionResult Index()
        {
            //int userID = 0;
            //if (User.Identity.IsAuthenticated)
            //{
            //    User user = UserService.GetUserByEmail(User.Identity.Name);
            //    if (user != null)
            //        userID = user.ID;
            //}
            //ViewBag.userID = userID;

            breadcrumbs.Add("#", Resource.Auctions);
            ViewBag.breadcrumbs = breadcrumbs;

            ExtendedSearchVM modelVM = new ExtendedSearchVM()
            {
                StatusID = 2,
                Type     = "auction"
            };

            return(View("~/Views/SearchAuto/SearchResult.cshtml", modelVM));
        }
Example #5
0
        public ActionResult Details(int id)
        {
            //Auto auto = AutoService.GetPublishedByID(id);
            Auto auto = AutoService.GetByID(id);

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

            auto.Views++;
            AutoService.Edit(auto);

            User currentUser = null;

            if (User.Identity.IsAuthenticated)
            {
                currentUser = UserService.GetUserByEmail(User.Identity.Name);
            }

            //double dollarRate = CurrencyService.GetCurrencyRate();

            AutoDetailsVM autoDetailsVM = auto;

            for (int i = 0; i < autoDetailsVM.AutoExchangesIncome.Count; i++)
            {
                autoDetailsVM.AutoExchangesIncome[i].DeleteButtonIsAvailable = (currentUser != null && (currentUser.ID == auto.UserID || currentUser.ID == autoDetailsVM.AutoExchangesIncome[i].Auto.Owner.UserID));
            }


            List <AutoShortInfoVM> autosAvailableForExchangeOffer = null;

            if (currentUser != null)
            {
                List <Auto> tmp = currentUser.Autoes.Where(a => /*a.StatusID == 2
                                                                 * &&*/a.AutoExchangesOutcome.FirstOrDefault(ex => ex.TargetAutoID == id) == null).ToList();
                autosAvailableForExchangeOffer = new List <AutoShortInfoVM>();
                foreach (var item in tmp)
                {
                    autosAvailableForExchangeOffer.Add(item);
                }

                ViewBag.currencies = CurrencyService.GetAllAsSelectList(1);
                //ViewBag.showAddtoFavoriteButton = true;

                if (currentUser.AutoFavorites.FirstOrDefault(f => f.AutoID == id) != null)
                {
                    ViewBag.isInFavorite = true;
                }

                if (currentUser.ID == autoDetailsVM.Owner.UserID)
                {
                    ViewBag.isAbleToAnswerToOffers = true;
                }
            }

            ViewBag.autosAvailableForExchangeOffer = autosAvailableForExchangeOffer;

            //breadcrumbs.Add("/Auto/Index", Resource.Advertisements);
            breadcrumbs.Add("/Auto/Index", autoDetailsVM.Region);
            breadcrumbs.Add("/Auto", autoDetailsVM.Make);
            breadcrumbs.Add("#", autoDetailsVM.Make + " " + autoDetailsVM.Model + " " + autoDetailsVM.YearOfIssue);
            ViewBag.breadcrumbs = breadcrumbs;

            //create search model for getting related
            ExtendedSearchVM searchVM = new ExtendedSearchVM()
            {
                //MakeAndModels = new List<MakeAndModelVM>() { new MakeAndModelVM() { MakeID = auto.MakeID, ModelID = auto.ModelID, ModelToBeExcluded = false } },
                MakeID = new int[1] {
                    auto.MakeID
                },
                ModelID = new int[1] {
                    auto.ModelID
                },
                MakeAndModels = new List <MakeAndModelVM>()
                {
                    new MakeAndModelVM()
                    {
                        MakeID = auto.MakeID, ModelID = auto.ModelID
                    }
                },
                YearOfIssueFrom = auto.YearOfIssue,
                YearOfIssueTo   = auto.YearOfIssue,
                IDsToBeExcluded = new int[1] {
                    auto.ID
                }
            };

            ViewBag.searchVM = searchVM;

            List <AutoPhotoVM> orderedPhotos = autoDetailsVM.AutoPhotoes.OrderByDescending(p => p.IsMain).ToList();
            AutoPhotoVM        mainPhoto     = orderedPhotos[0];

            ViewBag.orderedPhotos = orderedPhotos;

            //Open Graph (for fb share purposes)
            Dictionary <string, string> openGraph = new Dictionary <string, string>();

            openGraph["url"]         = "http://emcar.quadevs.com/Auto/Details/" + id;
            openGraph["type"]        = "page";
            openGraph["title"]       = autoDetailsVM.Make + " " + autoDetailsVM.Model + (!string.IsNullOrWhiteSpace(autoDetailsVM.Modification) ? autoDetailsVM.Modification : "") + " " + autoDetailsVM.YearOfIssue;
            openGraph["description"] = autoDetailsVM.Description;
            openGraph["image"]       = XCarsConfiguration.BucketEndpoint + XCarsConfiguration.BucketName + "/" + XCarsConfiguration.AutoPhotosUploadUrl + (mainPhoto.ID != 0 ? (mainPhoto.ID + "_575x359") : XCarsConfiguration.AutoNoPhotoName) + XCarsConfiguration.PhotoExtension;
            ViewBag.openGraph        = openGraph;

            return(View(autoDetailsVM));
        }
Example #6
0
        //[Authorize]
        public ActionResult Details(int id)
        {
            Auction auction = AuctionService.GetByID(id); //should be just GetByID(id)

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

            auction.Views++;
            AuctionService.Edit(auction);

            int  userID              = 0;
            bool currentUserIsOwner  = false;
            bool isActive            = false;
            bool auctionEnterIsPayed = false;

            if (User.Identity.IsAuthenticated)
            {
                User user = UserService.GetUserByEmail(User.Identity.Name);

                userID = user.ID;
                if (auction.Auto.UserID == user.ID)
                {
                    currentUserIsOwner = true;
                }

                if (user.AuctionFavorites.FirstOrDefault(f => f.AuctionID == id) != null)
                {
                    ViewBag.isInFavorite = true;
                }

                //check if user enter auction the first time
                //if (user.AuctionAgreement == false && !currentUserIsOwner)
                //    return RedirectToAction("TermsOfUse", new { id = id });
            }
            else
            {
                string setting = $"{XCarsConfiguration.AllowUnauthenticatedUserToEnterAuction}";
                if (!string.IsNullOrWhiteSpace(setting) && setting == "false")
                {
                    return(HttpNotFound());
                }
            }

            //try
            //{
            if (auction.StatusID == 2 && auction.Deadline > DateTime.Now)
            {
                isActive = true;
            }

            if (!currentUserIsOwner && !isActive)
            {
                //return RedirectToAction("Index", "Home");
                return(HttpNotFound());
            }

            //если пользователь еще не оплатил вход в этот аукцион, то снимаем деньги
            //если денег недостаточно, то перенаправляем на страницу пополнения баланса
            if (userID > 0 && !currentUserIsOwner)
            {
                //User user = UserService.GetUserByEmail(User.Identity.Name);
                //if (user.Payments.FirstOrDefault(p => p.Type == "AuctionEnter" && p.ObjectID == id) != null)
                //    auctionEnterIsPayed = true;
                //else
                //{
                //    decimal auctionEnterPrice = 0;
                //    string setting = $"{XCarsConfiguration.AuctionEnterPrice}";
                //    if (!string.IsNullOrWhiteSpace(setting))
                //        Decimal.TryParse(setting, out auctionEnterPrice);

                //    if (user.Balance >= auctionEnterPrice)
                //    {
                //        user.Balance -= auctionEnterPrice;
                //        user.Payments.Add(new Payment()
                //        {
                //            Amount = auctionEnterPrice,
                //            ObjectID = id,
                //            Type = "AuctionEnter",
                //            Description = Resource.AuctionEnterPayment
                //        });
                //        UserService.EditUser(user);

                //        int eligiblePeriodInMinutes = 0;
                //        string tmp = $"{XCarsConfiguration.XMinutesAuctionFinishEmailEligiblePeriod}";
                //        int.TryParse(tmp, out eligiblePeriodInMinutes);

                //        ScheduledEmail scheduledEmail = new ScheduledEmail()
                //        {
                //            DateScheduled = DateTime.Now,
                //            DateDue = auction.Deadline,
                //            //StatusID = 1,
                //            To = user.Email,
                //            Subject = "Subject1",
                //            Body = "Text1",
                //            ObjectTypeID = 2,
                //            ObjectID = auction.ID
                //        };
                //        scheduledEmail.DateEligible = scheduledEmail.DateDue.AddMinutes(eligiblePeriodInMinutes);
                //        ScheduledEmailService.Create(scheduledEmail);

                //        int minutes = 0;
                //        tmp = $"{XCarsConfiguration.XMinutesRemaingToAuctionDeadline}";
                //        int.TryParse(tmp, out minutes);

                //        eligiblePeriodInMinutes = 0;
                //        tmp = $"{XCarsConfiguration.XMinutesRemainingAuctionFinishEmailEligiblePeriod}";
                //        int.TryParse(tmp, out eligiblePeriodInMinutes);

                //        ScheduledEmail scheduledEmail2 = new ScheduledEmail()
                //        {
                //            DateScheduled = DateTime.Now,
                //            DateDue = auction.Deadline.AddMinutes(-1* minutes),
                //            //StatusID = 1,
                //            To = user.Email,
                //            Subject = "Subject1",
                //            Body = "Text1",
                //            ObjectTypeID = 3,
                //            ObjectID = auction.ID
                //        };
                //        scheduledEmail2.DateEligible = scheduledEmail2.DateDue.AddMinutes(eligiblePeriodInMinutes);
                //        ScheduledEmailService.Create(scheduledEmail2);
                //    }
                //    else
                //        return RedirectToAction("Pay", "Payment");
                //}
            }

            ViewBag.userID              = userID;
            ViewBag.currentUserIsOwner  = currentUserIsOwner;
            ViewBag.isActive            = isActive;
            ViewBag.auctionEnterIsPayed = auctionEnterIsPayed;
            ViewBag.UserNoPhotoUrl      = $"{XCarsConfiguration.UserNoPhotoUrl}";
            ViewBag.ImageSourceType     = $"{XCarsConfiguration.ImageSourceType}";

            AuctionDetailsVM auctionVM = auction;

            breadcrumbs.Add("/Auto/Index", auctionVM.Auto.Region);
            breadcrumbs.Add("/Auto", auctionVM.Auto.Make);
            breadcrumbs.Add("#", auctionVM.Auto.Make + " " + auctionVM.Auto.Model + " " + auctionVM.Auto.YearOfIssue);
            ViewBag.breadcrumbs = breadcrumbs;

            //create search model for getting related
            ExtendedSearchVM auctionSearchVM = new ExtendedSearchVM()
            {
                //MakeAndModels = new List<MakeAndModelVM>() { new MakeAndModelVM() { MakeID = auto.MakeID, ModelID = auto.ModelID, ModelToBeExcluded = false } },
                MakeID = new int[1] {
                    auction.Auto.MakeID
                },
                ModelID = new int[1] {
                    auction.Auto.ModelID
                },
                MakeAndModels = new List <MakeAndModelVM>()
                {
                    new MakeAndModelVM()
                    {
                        MakeID = auction.Auto.MakeID, ModelID = auction.Auto.ModelID
                    }
                },
                YearOfIssueFrom = auction.Auto.YearOfIssue,
                YearOfIssueTo   = auction.Auto.YearOfIssue,
                IDsToBeExcluded = new int[1] {
                    auction.ID
                },
                Type = "auction"
            };

            ViewBag.auctionSearchVM = auctionSearchVM;

            List <AuctionPhotoVM> orderedPhotos = auctionVM.AuctionPhotoes.OrderByDescending(p => p.IsMain).ToList();

            ViewBag.orderedPhotos = orderedPhotos;
            List <AutoPhotoVM> orderedAutoPhotos = auctionVM.Auto.AutoPhotoes.OrderByDescending(p => p.IsMain).ToList();

            ViewBag.orderedAutoPhotos = orderedAutoPhotos;

            AutoPhotoVM mainPhoto = orderedAutoPhotos[0];

            //Open Graph (for fb share purposes)
            Dictionary <string, string> openGraph = new Dictionary <string, string>();

            openGraph["url"]         = "http://emcar.quadevs.com/Auction/Details/" + id;
            openGraph["type"]        = "page";
            openGraph["title"]       = auctionVM.Auto.Make + " " + auctionVM.Auto.Model + (!string.IsNullOrWhiteSpace(auctionVM.Auto.Modification) ? auctionVM.Auto.Modification : "") + " " + auctionVM.Auto.YearOfIssue;
            openGraph["description"] = auctionVM.Auto.Description + " " + auctionVM.Description;
            openGraph["image"]       = XCarsConfiguration.BucketEndpoint + XCarsConfiguration.BucketName + "/" + XCarsConfiguration.AutoPhotosUploadUrl + (mainPhoto.ID != 0 ? (mainPhoto.ID + "_1024x768") : XCarsConfiguration.AutoNoPhotoName) + XCarsConfiguration.PhotoExtension;
            ViewBag.openGraph        = openGraph;

            ViewBag.deadlineZFormat = string.Format("{0}Z", auctionVM.Deadline.ToString("s"));

            return(View(auctionVM));
            //}
            //catch (Exception ex)
            //{
            //    return HttpNotFound();
            //}
        }
Example #7
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*/));
        }