コード例 #1
0
        public AuctionHub(IUserService userService, IAuctionService auctionService)
        {
            _userService    = userService;
            _auctionService = auctionService;

            _auctionProcess            = new AuctionProcess(_auctionService);
            _auctionProcess.SendState += SendState;
            _auctionProcess.Start();
        }
コード例 #2
0
        public ActionResult AddNewAuction(AuctionViewModel model)
        {
            Response response = new Response();

            if (ModelState.IsValid)
            {
                try
                {
                    var auction = _context.AuctionProcesses.Where(a => a.ItemId == model.ItemId && a.Bid < model.Bid).ToList();

                    AuctionProcess NewAuction = null;
                    var            item       = _context.Items.SingleOrDefault(i => i.Id == model.ItemId);
                    if (auction != null && auction.Count != 0)
                    {
                        var auc = auction.LastOrDefault();
                        NewAuction = new AuctionProcess
                        {
                            ItemId        = (int)model.ItemId,
                            ParticipantId = (int)model.ParticipantId,
                            Bid           = model.Bid,
                            Profit        = (model.Bid - item.StartPrice) - auc.Profit,
                            isWinner      = false,
                        };
                    }
                    else
                    {
                        NewAuction = new AuctionProcess
                        {
                            ItemId        = (int)model.ItemId,
                            ParticipantId = (int)model.ParticipantId,
                            Bid           = model.Bid,
                            Profit        = model.Bid - item.StartPrice,
                            isWinner      = false,
                        };
                    }

                    _context.AuctionProcesses.Add(NewAuction);
                    _context.SaveChanges();

                    response.Success = true;
                    response.Message = "Saved Successfully";
                }
                catch (Exception e)
                {
                    response.Success  = false;
                    response.Message += "Error => " + e.Message;
                    return(Json(response));
                }
            }
            else
            {
                foreach (var modelStateKey in ViewData.ModelState.Keys)
                {
                    var modelStateVal = ViewData.ModelState[modelStateKey];
                    foreach (var error in modelStateVal.Errors)
                    {
                        var key          = modelStateKey;
                        var errorMessage = error.ErrorMessage;
                        response.Message += key + " => " + error.ErrorMessage + "\n";
                    }
                }

                return(Json(response));
            }
            return(Json(response));
        }