public ActionResult SellCreature(int userCreatureId) { var userId = User.Identity.GetUserId(); var user = db.Users.Find(userId); if (user.UserCreatures.Any(uc => uc.Id == userCreatureId && !uc.InSquad) && user.UserCreatures.Count(uc => !uc.InAuction) > 1) { var userCreature = user.UserCreatures.First(uc => uc.Id == userCreatureId); var auctionCreatureViewModel = new AuctionCreatureViewModel { UserCreatureId = userCreatureId, Name = userCreature.Creature.Name, StartPrice = userCreature.Worth, Hours = 1 }; return(View(auctionCreatureViewModel)); } ; return(RedirectToAction("Index", "Creature")); }
public ActionResult SellCreature(AuctionCreatureViewModel model) { if (ModelState.IsValid && (model.BuyoutPrice != null && model.BuyoutPrice - model.StartPrice >= 50 || model.BuyoutPrice == null)) { var userId = User.Identity.GetUserId(); var user = db.Users.Find(userId); if (user.UserCreatures.Any(uc => uc.Id == model.UserCreatureId)) { var auctionCreature = new AuctionCreature { OwnerId = userId, UserCreatureId = model.UserCreatureId, StartPrice = model.StartPrice, BuyoutPrice = model.BuyoutPrice, EndTime = DateTimeOffset.Now.AddHours(model.Hours) }; db.AuctionCreatures.Add(auctionCreature); db.AuctionTargets.Add(new AuctionTarget { AuctionCreatureId = auctionCreature.Id, UserId = userId }); user.UserCreatures.First(uc => uc.Id == model.UserCreatureId).InAuction = true; db.SaveChanges(); } return(RedirectToAction("Index", "Creature")); } else if (model.BuyoutPrice != null && model.BuyoutPrice - model.StartPrice < 50) { ViewBag.Error = "Buyout Price needs to be 50 gold or more than Start Price"; } return(View()); }