Ejemplo n.º 1
0
        //[ResponseType(typeof(Model.City))]
        public IHttpActionResult AddToFavorites(int id)
        {
            User user = UserService.GetUserByEmail(User.Identity.Name);

            Auction auto = AuctionService.GetByID(id);

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

            try
            {
                int             result = 1;
                AuctionFavorite fav    = user.AuctionFavorites.FirstOrDefault(f => f.AuctionID == id);
                if (fav == null)
                {
                    user.AuctionFavorites.Add(new AuctionFavorite()
                    {
                        AuctionID = id
                    });
                    UserService.EditUser(user);
                }
                else
                {
                    AuctionFavoriteService.Delete(fav);
                    result = -1;
                }

                AuctionService.Edit(auto);
                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Create(AuctionCreateVM modelVM)
        {
            User user = UserService.GetUserByEmail(User.Identity.Name);
            Auto auto = user?.Autoes.FirstOrDefault(a => a.ID == modelVM.AutoID);

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

            Auction auction = AuctionService.GetUnactive(modelVM.ID);

            if (auction == null || auction.AutoID != auto.ID)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //auction.AutoID = modelVM.AutoID;
                    auction.StartPrice   = modelVM.StartPrice;
                    auction.CurrentPrice = modelVM.StartPrice;
                    auction.CurrencyID   = modelVM.CurrencyID;
                    auction.Description  = modelVM.Description;
                    auction.DateCreated  = DateTime.Now;
                    auction.Deadline     = DateTime.Now.AddHours(modelVM.Hours + modelVM.Days * 24);
                    //auction.Deadline = DateTime.Now.AddMinutes(modelVM.Hours);
                    //auction.Deadline = DateTime.Now.AddMinutes(2);
                    auction.StatusID = 2;

                    List <AuctionBid> bids = auction.AuctionBids.ToList();
                    foreach (var item in bids)
                    {
                        AuctionBidService.Delete(item);
                    }

                    //AuctionService.Edit(auction);
                    HangfireService.CancelJob(auction.DeletionJobID);
                    auction.CompletionJobID = HangfireService.CreateJobForAuction(auction);
                    AuctionService.Edit(auction);

                    return(RedirectToAction("Details", "Auction", new { id = auction.ID }));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", Resource.SaveError + ": " + ex.Message);
                }
            }
            else
            {
                ModelState.AddModelError("", Resource.InvalidData);
            }

            //ViewBag.autoID = auto.ID;
            //ViewBag.auctionID = auction.ID;
            ViewBag.currencies       = CurrencyService.GetAllAsSelectList();
            ViewBag.recommendedPrice = AuctionService.GetRecommendedPrice(auto.PriceUSD, auto.PriceUAH);

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

            int limit = 2000;

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

            return(View(modelVM));
        }
Ejemplo n.º 3
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();
            //}
        }