public static AuctionModel Auction(Auction auction)
 {
     var model = new AuctionModel()
         {
             Id = auction.Id,
             Caption = auction.Caption,
             Description = auction.Description,
             Price = auction.Price,
             Created = DateTime.Parse(auction.Created),
             LatestBid = auction.LatestBid,
             Bids = (auction.Bids.Select(b => new BidModel
                 {
                     NickName = "John Doe",
                     Id = b.Id,
                     Amount = b.Amount,
                     Created = DateTime.Parse(b.Created),
                     AuctionId = auction.Id,
                 })).ToList()
         };
     return model;
 }
Пример #2
0
 public HttpResponseMessage CreateNewAuction(AuctionModel newAuction)
 {
     return(_auctionRepository.CreateNewAuction(newAuction));
 }
Пример #3
0
 public SupplierController()
 {
     _auctionModel = new AuctionModel();
 }
Пример #4
0
 public void LifeOver()
 {
     instance = null;
 }
Пример #5
0
 public AuctionsController()
 {
     _transactionModel = new TransactionModel();
     _auctionModel     = new AuctionModel();
     _walletModel      = new WalletModel();
 }
 public ActionResult Edit(AuctionModel model)
 {
     return(View());
 }
Пример #7
0
        public string CreateBid(string userID, string auctionID, decimal newPrice)
        {
            User loggedUser = (User)Session["user"];

            if (loggedUser == null || loggedUser.ID.ToString() != userID)
            {
                return("#Error: Please log in to create bid.");
            }
            if (string.IsNullOrWhiteSpace(userID) || string.IsNullOrWhiteSpace(auctionID))
            {
                return("");
            }

            using (var ctx = new AuctionModel())
            {
                using (var transaction = ctx.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        Auction auction = ctx.GetAuction(auctionID);
                        if (auction == null)
                        {
                            throw new InvalidActionException("#Error: Invalid auction ID.");
                        }
                        if (auction.Owner.ToString() == loggedUser.ID.ToString())
                        {
                            throw new InvalidActionException("#Error: You can't bid on your own auction.");
                        }
                        if (auction.OpenedOn == null)
                        {
                            throw new InvalidActionException("#Error: Auction is not opened yet.");
                        }
                        if (auction.ClosedOn != null || auction.OpenedOn.Value.AddSeconds(auction.Duration) <= DateTime.Now.AddHours(2))
                        {
                            throw new InvalidActionException("#Error: Auction time has expired.");
                        }

                        var lastBid = auction.Bids.OrderByDescending(o => o.CreatedOn).ToList().FirstOrDefault();
                        if (lastBid != null && lastBid.Bidder.ToString() == loggedUser.ID.ToString())
                        {
                            throw new InvalidActionException("#Error: You are already last bidder.");
                        }
                        var currentPrice = lastBid?.TokenAmount ?? auction.StartingPrice;
                        if (currentPrice >= newPrice)
                        {
                            throw new InvalidActionException("#Error: You can't create bid with price equal or lower than current price.");
                        }

                        User user = ctx.FindUserByID(userID);
                        if (user.TokenAmount < newPrice)
                        {
                            throw new InvalidActionException("#Error: You don't have enough tokens to create bid.");
                        }

                        if (lastBid != null)
                        {
                            lastBid.User.TokenAmount += lastBid.TokenAmount;
                        }
                        user.TokenAmount -= newPrice;

                        Bid bid = new Bid
                        {
                            ID          = Guid.NewGuid(),
                            Bidder      = user.ID,
                            OnAuction   = auction.ID,
                            CreatedOn   = DateTime.Now.AddHours(2),
                            TokenAmount = newPrice
                        };

                        ctx.Bids.Add(bid);
                        ctx.SaveChanges();
                        transaction.Commit();
                        AuctionHub.HubContext.Clients.All.refreshLastBidder(auction.ID.ToString(), newPrice, user.FirstName + " " + user.LastName, user.ID.ToString());
                        AuctionHub.HubContext.Clients.All.newBid(auction.ID.ToString(), newPrice.ToString("F4"), user.FirstName + " " + user.LastName, user.ID.ToString(), bid.CreatedOn.ToString("dd.MM.yyyy - HH:mm:ss"));
                        return("You have successfully created bid.");
                    }
                    catch (InvalidActionException e)
                    {
                        transaction.Rollback();
                        logger.Error(e.Message);
                        return(e.Message);
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        logger.Error(e.Message);
                        return(e.Message);
                    }
                }
            }
        }
Пример #8
0
 public AuctionController()
 {
     _auctionModel = new AuctionModel();
 }
Пример #9
0
        public string CreateAuction(string productname, decimal startingprice, int?auctionduration)
        {
            if (!(Session["user"] is User user))
            {
                return("");
            }
            if (string.IsNullOrWhiteSpace(productname))
            {
                return("#Error: You must provide product name!");
            }
            if (startingprice <= 0)
            {
                return("#Error: You must provide starting price greater than zero!");
            }
            if (auctionduration != null && auctionduration <= 0)
            {
                return("#Error: You must provide auction duration greater than zero!");
            }
            if (auctionduration <= 0)
            {
                return("#Error: You must provide auction duration greater than zero!");
            }

            Guid guid = Guid.NewGuid();

            if (Request.Files["image"] != null && Request.Files["image"].ContentType == "image/png")
            {
                Directory.CreateDirectory(Server.MapPath("~/resources/storage/auctions/" + guid.ToString() + "/"));
                Request.Files["image"].SaveAs(Server.MapPath("~/resources/storage/auctions/" + guid.ToString() + "/image.png"));
            }
            else
            {
                return("#Error: You must provide one .png picture of product!");
            }

            using (var ctx = new AuctionModel())
            {
                try
                {
                    SystemParameter system  = ctx.GetSystemParameters();
                    Auction         auction = new Auction
                    {
                        ID            = guid,
                        Title         = productname,
                        Duration      = auctionduration ?? system.AuctionDuration,
                        Currency      = system.Currency,
                        TokenValue    = system.TokenValue,
                        StartingPrice = startingprice,
                        CreatedOn     = DateTime.Now.AddHours(2),
                        Owner         = user.ID
                    };
                    ctx.Auctions.Add(auction);
                    ctx.SaveChanges();
                    AuctionHub.HubContext.Clients.All.onCreateAuction(auction.ID.ToString(), auction.Title, 0, auction.StartingPrice, "", "", 0, 1);
                    return("You have successfully created auction.");
                }
                catch (Exception e)
                {
                    logger.Error(e.Message);
                    return("#Error: Internal server error.");
                }
            }
        }
Пример #10
0
        public ActionResult Notify(string reference, string status)
        {
            using (var ctx = new AuctionModel())
            {
                using (var transaction = ctx.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        TokenOrder order = ctx.FindTokenOrderByID(reference);
                        if (order == null)
                        {
                            throw new Exception("Invalid order. ID = " + reference);
                        }
                        if (order.State != 0)
                        {
                            throw new Exception("Order already processed. ID = " + reference);
                        }
                        switch (status)
                        {
                        case "success":
                            order.State = 1;
                            break;

                        case "failed":
                            order.State = 2;
                            break;

                        case "canceled":
                            order.State = 2;
                            break;
                        }
                        User user = ctx.FindUserByID(order.Buyer.ToString());
                        if (order.State == 1)
                        {
                            user.TokenAmount += order.TokenAmount;
                        }
                        ctx.SaveChanges();
                        transaction.Commit();
                        AuctionHub.HubContext.Clients.All.onNotify(user.ID.ToString(), order.ID.ToString(), order.State, user.TokenAmount.ToString("F4"));

                        try
                        {
                            Utility.SendEmail(user.Email, "Transaction processed #" + reference,
                                              "Hello " + user.FirstName + "," +
                                              Environment.NewLine + Environment.NewLine +
                                              "Your transaction #" + order.ID.ToString() + " has been processed." + Environment.NewLine +
                                              (order.State == 1 ? "Status: COMPLETED" : "Status: CANCELED") + Environment.NewLine + Environment.NewLine +
                                              "Sincerely, " + Environment.NewLine +
                                              "The Auction Website Team"
                                              );
                        }
                        catch (Exception e)
                        {
                            logger.Error(e.Message);
                        }
                    }
                    catch (Exception e)
                    {
                        logger.Error(e.Message);
                        transaction.Rollback();
                        ViewBag.ErrorMsg = "Internal server error.";
                        return(View("Error"));
                    }
                }
            }
            return(RedirectToAction("Profile"));
        }
Пример #11
0
 public SellerWrapper()
 {
     auctionContext = new AuctionModel();
 }
Пример #12
0
 public ProductController()
 {
     _auctionModel = new AuctionModel();
 }
Пример #13
0
 public async Task <ActionResult> Save(AuctionModel model)
 {
     return(await Save <Auction>(model));
 }
Пример #14
0
 public HttpResponseMessage UpdateAuction(AuctionModel model)
 {
     return(_auctionRepository.UpdateAuction(model));
 }
Пример #15
0
        public string FinishAuction(string userID, string auctionID)
        {
            User loggedUser = (User)Session["user"];

            if (loggedUser == null || loggedUser.ID.ToString() != userID)
            {
                return("#Error: Please log in to finish auction.");
            }
            if (string.IsNullOrWhiteSpace(userID) || string.IsNullOrWhiteSpace(auctionID))
            {
                return("");
            }

            using (var ctx = new AuctionModel())
            {
                using (var transaction = ctx.Database.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        Auction auction = ctx.GetAuction(auctionID);
                        if (auction == null)
                        {
                            throw new InvalidActionException("#Error: Invalid auction ID.");
                        }
                        if (auction.Owner.ToString() != loggedUser.ID.ToString())
                        {
                            throw new InvalidActionException("#Error: You can't finish auction you didn't create.");
                        }
                        if (auction.OpenedOn == null)
                        {
                            throw new InvalidActionException("#Error: Auction is not opened yet.");
                        }
                        if (auction.ClosedOn != null)
                        {
                            throw new InvalidActionException("#Error: Auction is already finished.");
                        }
                        if (auction.OpenedOn.Value.AddSeconds(auction.Duration) >= DateTime.Now.AddHours(2))
                        {
                            throw new InvalidActionException("#Error: Wait for auction time to expire.");
                        }

                        auction.ClosedOn = DateTime.Now.AddHours(2);
                        var lastBid = auction.Bids.OrderByDescending(o => o.CreatedOn).ToList().FirstOrDefault();
                        if (lastBid != null)
                        {
                            User user = ctx.FindUserByID(userID);
                            user.TokenAmount += lastBid.TokenAmount;
                        }

                        ctx.SaveChanges();
                        transaction.Commit();
                        AuctionHub.HubContext.Clients.All.onFinishAuction(auction.ID.ToString(), auction.ClosedOn.Value.ToString("dd.MM.yyyy - HH:mm:ss"));
                        return("You have successfully finished auction.");
                    }
                    catch (InvalidActionException e)
                    {
                        transaction.Rollback();
                        logger.Error(e.Message);
                        return(e.Message);
                    }
                    catch (Exception e)
                    {
                        transaction.Rollback();
                        logger.Error(e.Message);
                        return(e.Message);
                    }
                }
            }
        }
Пример #16
0
        protected virtual void PrepareAuctionModel(AuctionModel model, Auction auction,
                                                   bool setPredefinedValues, bool excludeProperties)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            //if (auction != null)
            //{
            //    var parentGroupedProduct = _productService.GetProductById(auction.ParentGroupedProductId);
            //    if (parentGroupedProduct != null)
            //    {
            //        model.AssociatedToProductId = auction.ParentGroupedProductId;
            //        model.AssociatedToProductName = parentGroupedProduct.Name;
            //    }
            //}

            model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
            //model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name;
            //model.BaseDimensionIn = _measureService.GetMeasureDimensionById(_measureSettings.BaseDimensionId).Name;
            if (auction != null)
            {
                model.CreatedOn = _dateTimeHelper.ConvertToUserTime(auction.CreatedOnUtc, DateTimeKind.Utc);
                model.UpdatedOn = _dateTimeHelper.ConvertToUserTime(auction.UpdatedOnUtc, DateTimeKind.Utc);
            }

            ////little performance hack here
            ////there's no need to load attributes, categories, manufacturers when creating a new product
            ////anyway they're not used (you need to save a product before you map add them)
            //if (auction != null)
            //{
            //    foreach (var productAttribute in _productAttributeService.GetAllProductAttributes())
            //    {
            //        model.AvailableProductAttributes.Add(new SelectListItem
            //        {
            //            Text = productAttribute.Name,
            //            Value = productAttribute.Id.ToString()
            //        });
            //    }
            //    foreach (var manufacturer in _manufacturerService.GetAllManufacturers(showHidden: true))
            //    {
            //        model.AvailableManufacturers.Add(new SelectListItem
            //        {
            //            Text = manufacturer.Name,
            //            Value = manufacturer.Id.ToString()
            //        });
            //    }
            //    var allCategories = _categoryService.GetAllCategories(showHidden: true);
            //    foreach (var category in allCategories)
            //    {
            //        model.AvailableCategories.Add(new SelectListItem
            //        {
            //            Text = category.GetFormattedBreadCrumb(allCategories),
            //            Value = category.Id.ToString()
            //        });
            //    }
            //}

            ////copy product
            //if (auction != null)
            //{
            //    model.CopyProductModel.Id = auction.Id;
            //    model.CopyProductModel.Name = "Copy of " + auction.Name;
            //    model.CopyProductModel.Published = true;
            //    model.CopyProductModel.CopyImages = true;
            //}

            ////templates
            //var templates = _productTemplateService.GetAllProductTemplates();
            //foreach (var template in templates)
            //{
            //    model.AvailableProductTemplates.Add(new SelectListItem
            //    {
            //        Text = template.Name,
            //        Value = template.Id.ToString()
            //    });
            //}

            //vendors
            //model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;
            model.AvailableVendors.Add(new SelectListItem
            {
                Text  = _localizationService.GetResource("Admin.Catalog.Products.Fields.Vendor.None"),
                Value = "0"
            });
            var vendors = _vendorService.GetAllVendors(showHidden: true);

            foreach (var vendor in vendors)
            {
                model.AvailableVendors.Add(new SelectListItem
                {
                    Text  = vendor.Name,
                    Value = vendor.Id.ToString()
                });
            }

            ////delivery dates
            //model.AvailableDeliveryDates.Add(new SelectListItem
            //{
            //    Text = _localizationService.GetResource("Admin.Catalog.Products.Fields.DeliveryDate.None"),
            //    Value = "0"
            //});
            //var deliveryDates = _shippingService.GetAllDeliveryDates();
            //foreach (var deliveryDate in deliveryDates)
            //{
            //    model.AvailableDeliveryDates.Add(new SelectListItem
            //    {
            //        Text = deliveryDate.Name,
            //        Value = deliveryDate.Id.ToString()
            //    });
            //}

            ////warehouses
            //var warehouses = _shippingService.GetAllWarehouses();
            //model.AvailableWarehouses.Add(new SelectListItem
            //{
            //    Text = _localizationService.GetResource("Admin.Catalog.Products.Fields.Warehouse.None"),
            //    Value = "0"
            //});
            //foreach (var warehouse in warehouses)
            //{
            //    model.AvailableWarehouses.Add(new SelectListItem
            //    {
            //        Text = warehouse.Name,
            //        Value = warehouse.Id.ToString()
            //    });
            //}

            ////multiple warehouses
            //foreach (var warehouse in warehouses)
            //{
            //    var pwiModel = new ProductModel.ProductWarehouseInventoryModel
            //    {
            //        WarehouseId = warehouse.Id,
            //        WarehouseName = warehouse.Name
            //    };
            //    if (auction != null)
            //    {
            //        var pwi = auction.ProductWarehouseInventory.FirstOrDefault(x => x.WarehouseId == warehouse.Id);
            //        if (pwi != null)
            //        {
            //            pwiModel.WarehouseUsed = true;
            //            pwiModel.StockQuantity = pwi.StockQuantity;
            //            pwiModel.ReservedQuantity = pwi.ReservedQuantity;
            //            pwiModel.PlannedQuantity = _shipmentService.GetQuantityInShipments(auction, pwi.WarehouseId, true, true);
            //        }
            //    }
            //    model.ProductWarehouseInventoryModels.Add(pwiModel);
            //}

            ////product tags
            //if (auction != null)
            //{
            //    var result = new StringBuilder();
            //    for (int i = 0; i < auction.ProductTags.Count; i++)
            //    {
            //        var pt = auction.ProductTags.ToList()[i];
            //        result.Append(pt.Name);
            //        if (i != auction.ProductTags.Count - 1)
            //            result.Append(", ");
            //    }
            //    model.ProductTags = result.ToString();
            //}

            ////tax categories
            //var taxCategories = _taxCategoryService.GetAllTaxCategories();
            //model.AvailableTaxCategories.Add(new SelectListItem { Text = "---", Value = "0" });
            //foreach (var tc in taxCategories)
            //    model.AvailableTaxCategories.Add(new SelectListItem { Text = tc.Name, Value = tc.Id.ToString(), Selected = auction != null && !setPredefinedValues && tc.Id == auction.TaxCategoryId });

            ////baseprice units
            //var measureWeights = _measureService.GetAllMeasureWeights();
            //foreach (var mw in measureWeights)
            //    model.AvailableBasepriceUnits.Add(new SelectListItem { Text = mw.Name, Value = mw.Id.ToString(), Selected = auction != null && !setPredefinedValues && mw.Id == auction.BasepriceUnitId });
            //foreach (var mw in measureWeights)
            //    model.AvailableBasepriceBaseUnits.Add(new SelectListItem { Text = mw.Name, Value = mw.Id.ToString(), Selected = auction != null && !setPredefinedValues && mw.Id == auction.BasepriceBaseUnitId });

            ////specification attributes
            //var specificationAttributes = _specificationAttributeService.GetSpecificationAttributes();
            //for (int i = 0; i < specificationAttributes.Count; i++)
            //{
            //    var sa = specificationAttributes[i];
            //    model.AddSpecificationAttributeModel.AvailableAttributes.Add(new SelectListItem { Text = sa.Name, Value = sa.Id.ToString() });
            //    if (i == 0)
            //    {
            //        //attribute options
            //        foreach (var sao in _specificationAttributeService.GetSpecificationAttributeOptionsBySpecificationAttribute(sa.Id))
            //            model.AddSpecificationAttributeModel.AvailableOptions.Add(new SelectListItem { Text = sao.Name, Value = sao.Id.ToString() });
            //    }
            //}
            ////default specs values
            //model.AddSpecificationAttributeModel.ShowOnProductPage = true;

            ////discounts
            //model.AvailableDiscounts = _discountService
            //    .GetAllDiscounts(DiscountType.AssignedToSkus, showHidden: true)
            //    .Select(d => d.ToModel())
            //    .ToList();
            //if (!excludeProperties && auction != null)
            //{
            //    model.SelectedDiscountIds = auction.AppliedDiscounts.Select(d => d.Id).ToArray();
            //}

            ////default values
            //if (setPredefinedValues)
            //{
            //    model.MaximumCustomerEnteredPrice = 1000;
            //    model.MaxNumberOfDownloads = 10;
            //    model.RecurringCycleLength = 100;
            //    model.RecurringTotalCycles = 10;
            //    model.RentalPriceLength = 1;
            //    model.StockQuantity = 10000;
            //    model.NotifyAdminForQuantityBelow = 1;
            //    model.OrderMinimumQuantity = 1;
            //    model.OrderMaximumQuantity = 10000;

            //    model.UnlimitedDownloads = true;
            //    model.IsShipEnabled = true;
            //    model.AllowCustomerReviews = true;
            //    model.Published = true;
            //    model.VisibleIndividually = true;
            //}
        }
Пример #17
0
 public BidderController()
 {
     _auctionModel = new AuctionModel();
 }
Пример #18
0
 public ActionResult Create(AuctionModel model)
 {
     return(View());
 }
Пример #19
0
 public Task <HttpResponseMessage> CreateAuction(AuctionModel model)
 {
     return(_api.CreateAuction(model));
 }
Пример #20
0
 public ActionResult Delete(AuctionModel model)
 {
     return(View());
 }
Пример #21
0
 public Task <HttpResponseMessage> EditAuction(AuctionModel model)
 {
     return(_api.EditAuction(model));
 }
Пример #22
0
        public ActionResult Create()
        {
            var std = new AuctionModel();

            return(View(std));
        }
Пример #23
0
 public BuyerWrapper()
 {
     auctionModel = new AuctionModel();
 }
Пример #24
0
        public IActionResult EditAuction(AuctionModel updatedModel)
        {
            var result = _businessService.EditAuction(updatedModel);

            return(RedirectToAction("Dashboard", "Admin"));
        }
 public AuctionController(AuctionModel auctionModel)
 {
     _auctionModel = auctionModel;
 }