Ejemplo n.º 1
0
 public async Task <ActionResult> CreateMarketItem()
 {
     return(View(new CreateMarketItemModel
     {
         Currencies = await CurrencyReader.GetCurrencies(),
         Categories = await MarketplaceReader.GetMarketCategories()
     }));
 }
Ejemplo n.º 2
0
        public async Task <ActionResult> SubmitMarketItem(CreateMarketItemModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Currencies = await CurrencyReader.GetCurrencies();

                model.Categories = await MarketplaceReader.GetMarketCategories();

                return(View("CreateMarketItem", model));
            }

            var mainImage = await model.MainImage.SaveMarketItemImageToDiskAsync(true);

            var altimage1 = await model.AltImage1.SaveMarketItemImageToDiskAsync(false);

            var altimage2 = await model.AltImage2.SaveMarketItemImageToDiskAsync(false);

            var altimage3 = await model.AltImage3.SaveMarketItemImageToDiskAsync(false);

            var altimage4 = await model.AltImage4.SaveMarketItemImageToDiskAsync(false);

            var marketItem = new CreateMarketModel
            {
                Type            = model.Type,
                CategoryId      = model.GetCategoryId(),
                Title           = model.Title,
                CurrencyId      = model.CurrencyId,
                MainImage       = mainImage,
                AlternateImages = new List <string> {
                    altimage1, altimage2, altimage3, altimage4
                },
                AskingPrice                  = model.Price,
                ReservePrice                 = model.ReservePrice,
                Description                  = model.Description,
                LocationRegion               = model.LocationRegion,
                AllowPickup                  = model.AllowPickup,
                PickupOnly                   = model.PickupOnly,
                LocationId                   = model.GetLocationId(),
                ShippingBuyerArrange         = model.ShippingBuyerArrange,
                ShippingNational             = model.ShippingNational,
                ShippingInternational        = model.ShippingInternational,
                ShippingNationalPrice        = model.ShippingNationalPrice,
                ShippingNationalDetails      = model.ShippingNationalDetails,
                ShippingInternationalPrice   = model.ShippingInternationalPrice,
                ShippingInternationalDetails = model.ShippingInternationalDetails,
                CloseDate = DateTime.UtcNow.AddDays(model.Type == MarketItemType.Auction ? Math.Max(3, model.AuctionDuration) : 14)
            };


            var result = await MarketplaceWriter.CreateMarketItem(User.Identity.GetUserId(), marketItem);

            if (!result.Success)
            {
                return(ViewMessage(new ViewMessageModel(ViewMessageType.Danger, Resources.Market.itemActionErrorMessageTitle, Resources.Market.createItemErrorMessage)));
            }

            return(RedirectToAction("MarketItem", new { marketItemId = result.Result }));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> EditMarketItem(int marketItemId, bool isRelisting = false)
        {
            var response = await MarketplaceReader.GetMarketItem(marketItemId);

            if (response == null)
            {
                return(RedirectToAction("Index"));
            }

            var currentUser = new Guid(User.Identity.GetUserId());

            if (response.UserId != currentUser)
            {
                return(RedirectToAction("MarketItem", new { marketItemId = marketItemId }));
            }

            var marketItem = new EditMarketItemModel
            {
                Title            = response.Title,
                Id               = response.Id,
                Type             = response.Type,
                CategoryId       = response.CategoryId,
                Price            = response.AskingPrice,
                Description      = response.Description,
                CurrentMainImage = response.MainImage,
                CurrentAltImage1 = response.AlternateImages.Take(1).FirstOrDefault(),
                CurrentAltImage2 = response.AlternateImages.Skip(1).Take(1).FirstOrDefault(),
                CurrentAltImage3 = response.AlternateImages.Skip(2).Take(1).FirstOrDefault(),
                CurrentAltImage4 = response.AlternateImages.Skip(3).Take(1).FirstOrDefault(),
                CurrencyId       = response.CurrencyId,
                //   Feature = response.MarketItem.Feature,
                CityId                       = response.GetCityId(),
                CountryId                    = response.GetCountryId(),
                ReservePrice                 = response.ReservePrice,
                LocationRegion               = response.LocationRegion,
                AllowPickup                  = response.AllowPickup,
                PickupOnly                   = response.PickupOnly,
                ShippingBuyerArrange         = response.ShippingBuyerArrange,
                ShippingNational             = response.ShippingNational,
                ShippingInternational        = response.ShippingInternational,
                ShippingNationalPrice        = response.ShippingNationalPrice,
                ShippingNationalDetails      = response.ShippingNationalDetails,
                ShippingInternationalPrice   = response.ShippingInternationalPrice,
                ShippingInternationalDetails = response.ShippingInternationalDetails,
                IsRelisting                  = isRelisting,
                HasBids                      = response.Bids != null && response.Bids.Any(),
                Currencies                   = await CurrencyReader.GetCurrencies(),
                Categories                   = await MarketplaceReader.GetMarketCategories()
            };

            marketItem.SetCategories(response);

            return(View(marketItem));
        }
Ejemplo n.º 4
0
        public async Task <JsonResult> GetCategories(int parentId)
        {
            var data = await MarketplaceReader.GetMarketCategories();

            var categories = new List <SelectListItem>();

            categories.Add(new SelectListItem {
                Text = Cryptopia.Resources.General.PleaseSelectOption, Value = "-2"
            });
            foreach (var item in data.Where(x => x.ParentId == parentId))
            {
                categories.Add(new SelectListItem {
                    Text = item.DisplayName, Value = item.Id.ToString()
                });
            }
            return(Json(new SelectList(categories, "Value", "Text")));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Index(int?categoryId, int?currencyId, int?locationId, string sortBy, string searchTerm, int?page, MarketItemType?type)
        {
            var searchModel = new MarketItemSearchModel
            {
                CategoryId   = categoryId.HasValue ? categoryId.Value : 0,
                LocationId   = locationId.HasValue ? locationId.Value : 0,
                CurrencyId   = currencyId.HasValue ? currencyId.Value : 0,
                SortBy       = sortBy,
                ItemType     = type,
                SearchTerm   = searchTerm,
                Page         = page.HasValue ? page.Value : 1,
                ItemsPerPage = 24                 //TODO: UI selectable item count??
            };

            var response = await MarketplaceReader.GetMarketItems(searchModel);

            if (categoryId != Constant.MARKETPLACE_CATEGORY_ADULT)
            {
                response = response.Where(x => !x.IsAdult).ToList();
            }

            var pagedItems = response.Skip(searchModel.ItemsPerPage * (searchModel.Page - 1)).Take(searchModel.ItemsPerPage);
            var model      = new MarketPlaceModel
            {
                CategoryId  = categoryId.HasValue ? categoryId.Value : 0,
                LocationId  = locationId.HasValue ? locationId.Value : 0,
                CurrencyId  = currencyId.HasValue ? currencyId.Value : 0,
                ItemType    = type == null ? Cryptopia.Resources.Market.itemTypeAll : type.ToString(),
                SortBy      = string.IsNullOrEmpty(sortBy) ? Resources.Market.marketItemSortyByTitle : sortBy,
                SearchTerm  = searchTerm,
                Categories  = await MarketplaceReader.GetMarketCategories(),
                MarketItems = new StaticPagedList <MarketListItemModel>(pagedItems, Math.Max(searchModel.Page, 1), searchModel.ItemsPerPage, response.Count),
                Locations   = StaticDataCache.Locations.Where(x => x.ParentId == 0).OrderBy(x => x.Name).ToList(),
                Currencies  = await CurrencyReader.GetCurrencies()
            };

            return(View("MarketPlace", model));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> MarketItem(int marketItemId)
        {
            var response = await MarketplaceReader.GetMarketItem(marketItemId);

            if (response == null)
            {
                return(RedirectToAction("Index"));
            }

            var currentUser = new Guid(User.Identity?.GetUserId() ?? Guid.Empty.ToString());

            response.AlternateImages.Add(response.MainImage);
            var marketItem = new MarketItemModel
            {
                IsUserListing                = (User.Identity.IsAuthenticated && response.UserId == currentUser),
                IsUserBuyer                  = response.BuyerUserId.HasValue && (User.Identity.IsAuthenticated && response.BuyerUserId.Value == currentUser),
                Title                        = response.Title,
                Id                           = response.Id,
                CategoryId                   = response.CategoryId,
                Symbol                       = response.Symbol,
                AskingPrice                  = response.AskingPrice,
                Description                  = response.Description,
                MainImage                    = response.MainImage,
                AlternateImages              = response.AlternateImages,
                CloseDate                    = response.CloseDate,
                Created                      = response.Created,
                CurrencyId                   = response.CurrencyId,
                Feature                      = response.Feature,
                Location                     = response.Location,
                Questions                    = response.Questions,
                ReservePrice                 = response.ReservePrice,
                CurrentBidPrice              = response.CurrentBidPrice,
                Bids                         = response.Bids,
                Status                       = response.Status,
                Type                         = response.Type,
                UserName                     = response.UserName,
                AllowPickup                  = response.AllowPickup,
                PickupOnly                   = response.PickupOnly,
                ShippingBuyerArrange         = response.ShippingBuyerArrange,
                ShippingNational             = response.ShippingNational,
                ShippingInternational        = response.ShippingInternational,
                ShippingNationalPrice        = response.ShippingNationalPrice,
                ShippingNationalDetails      = response.ShippingNationalDetails,
                ShippingInternationalPrice   = response.ShippingInternationalPrice,
                ShippingInternationalDetails = response.ShippingInternationalDetails,
                HasBuyersFeedback            = response.HasBuyersFeedback,
                HasSellersFeedback           = response.HasSellersFeedback,
                SellersTrustRating           = response.UserTrustRating,
                BuyerUserName                = response.BuyerUserName,
                BuyersTrustRating            = response.BuyerTrustRating,
                IsAuction                    = response.Type == MarketItemType.Auction,
                NoReserve                    = response.ReservePrice <= 0,
                ReserveMet                   = response.CurrentBidPrice >= response.ReservePrice,
            };

            var output = new MarketPlaceModel
            {
                CategoryId = marketItem.CategoryId,
                Categories = await MarketplaceReader.GetMarketCategories(),
                Locations  = StaticDataCache.Locations.Where(x => x.ParentId == 0).OrderBy(x => x.Name).ToList(),
                Currencies = await CurrencyReader.GetCurrencies(),
                SortBy     = Resources.Market.marketItemSortyByTitle,
                MarketItem = marketItem
            };

            return(View("MarketPlace", output));
        }