Esempio n. 1
0
        public ActionResult Publish(int id) //auction ID
        {
            User    user    = UserService.GetUserByEmail(User.Identity.Name);
            Auction auction = AuctionService.GetByID(id);

            if (auction == null || auction.Auto.UserID != user.ID)
            {
                return(HttpNotFound());
            }

            ViewBag.currencies       = CurrencyService.GetAllAsSelectList();
            ViewBag.recommendedPrice = AuctionService.GetRecommendedPrice(auction.Auto.PriceUSD, auction.Auto.PriceUAH);

            AuctionCreateVM auctionCreateVM = auction;

            AutoDetailsVM      autoVM        = auction.Auto;
            List <AutoPhotoVM> orderedPhotos = autoVM.AutoPhotoes.OrderByDescending(p => p.IsMain).ToList();
            AutoPhotoVM        mainPhoto     = orderedPhotos[0];

            ViewBag.mainPhoto = mainPhoto;

            ViewBag.autoVM = autoVM;

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

            int limit = 2000;

            int.TryParse(XCarsConfiguration.AutoDescriptionMaxLength, out limit);
            ViewBag.autoDescriptionMaxLength = limit;

            return(View("Create", auctionCreateVM));
        }
Esempio n. 2
0
        public ActionResult Create(int id) //auto ID
        {
            User user = UserService.GetUserByEmail(User.Identity.Name);
            Auto auto = user?.Autoes.FirstOrDefault(a => a.ID == id && a.StatusID == 2);

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

            Auction auction = new Auction()
            {
                AutoID         = auto.ID,
                DateCreated    = DateTime.Now,
                StartPrice     = 0,
                CurrentPrice   = 0,
                PriceUSDSearch = 0,
                PriceUAHSearch = 0,
                CurrencyID     = 1,
                StatusID       = 1, //draft
                Deadline       = DateTime.Now
            };

            AuctionService.Create(auction);
            //string jobID = HangfireService.CreateJobForAuctionDeletion(auction);
            //auction.DeletionJobID = jobID;
            //AuctionService.Edit(auction);

            ViewBag.currencies       = CurrencyService.GetAllAsSelectList();
            ViewBag.recommendedPrice = AuctionService.GetRecommendedPrice(auto.PriceUSD, auto.PriceUAH);

            AuctionCreateVM auctionCreateVM = auction;

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

            ViewBag.mainPhoto = mainPhoto;

            ViewBag.autoVM = autoVM;

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

            int limit = 2000;

            int.TryParse(XCarsConfiguration.AutoDescriptionMaxLength, out limit);
            ViewBag.autoDescriptionMaxLength = limit;

            return(View(auctionCreateVM));
        }
Esempio n. 3
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));
        }
Esempio n. 4
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();
            //}
        }