public ActionResult Edit(BountyCreateViewModel bountyCreateViewModel) { var loggedInUserId = this.bounty.GetLoggedInUserId(); bountyCreateViewModel.Bounty = this.db.Bounties.Find(bountyCreateViewModel.Bounty.Id); bountyCreateViewModel.Character = this.db.Characters.Find(bountyCreateViewModel.Bounty.PlacedOnId); ModelState["Character.Name"].Errors.Clear(); if(this.bounty.IsBountyOwner(loggedInUserId, bountyCreateViewModel.Bounty.Id) && this.bounty.GetStatus(bountyCreateViewModel.Bounty.Id) == "Placement Pending") { if(ModelState.IsValid) { this.bounty = bountyCreateViewModel.Bounty; this.db.Entry(this.bounty).State = EntityState.Modified; this.bounty.PlacedOnId = bountyCreateViewModel.Bounty.PlacedOnId; this.bounty.Amount = bountyCreateViewModel.Bounty.Amount; this.bounty.Reason = bountyCreateViewModel.Bounty.Reason; this.bounty.Message = bountyCreateViewModel.Bounty.Message; this.bounty.PlacedById = bountyCreateViewModel.SelectedCharacter; this.db.SaveChanges(); return RedirectToAction("Details", new { id = bountyCreateViewModel.Bounty.Id }); } else { var viewModel = new BountyCreateViewModel { Bounty = bountyCreateViewModel.Bounty, Character = bountyCreateViewModel.Character, SelectedCharacter = bountyCreateViewModel.Bounty.PlacedById }; return View("Edit", viewModel); } } else { return RedirectToAction("Details", new { id = bountyCreateViewModel.Bounty.Id }); } }
public ActionResult Create(Guid id, BountyCreateViewModel bountyCreateViewModel) { Character character = this.db.Characters.Find(id); var accountId = this.account.GetLoggedInUserId(); // Check if character has bounty on them if(this.bounty.IsActiveBountyOnCharacter(character.Id) == true) { ModelState.AddModelError(string.Empty, "A bounty has already been placed on this character"); } if(ModelState.IsValid) { this.bounty.Id = Guid.NewGuid(); this.bounty.Amount = bountyCreateViewModel.Bounty.Amount; this.bounty.Reason = bountyCreateViewModel.Bounty.Reason; this.bounty.Message = bountyCreateViewModel.Bounty.Message; this.bounty.PlacedById = bountyCreateViewModel.SelectedCharacter; this.bounty.PlacedOnId = character.Id; this.bounty.DatePlaced = DateTime.Now; this.bounty.IsPlacementPending = true; this.bounty.DateCompleted = null; this.bounty.IsCompletionPending = null; this.bounty.KilledById = null; this.bounty.KillShotImageId = null; this.db.Bounties.Add(this.bounty); this.db.SaveChanges(); // Send email notification this.emailNotificationHelper.SendBountyNotificationEmail(this.bounty, "Pending Placement"); // Add notification message this.message.AddBountyNotificationMessage(this.bounty, "Pending Placement"); return RedirectToAction("Dashboard", "Home"); } else { this.characterAddEditViewModel.Character = this.db.Characters.Find(character.Id); var viewModel = new BountyCreateViewModel { Character = this.characterAddEditViewModel.Character, SelectedCharacter = bountyCreateViewModel.SelectedCharacter }; return View(viewModel); } }
public ActionResult Edit(Guid id) { if(this.bounty.IsBountyOwner(this.account.GetLoggedInUserId(), id)) { BountyCreateViewModel bountyCreateViewModel = new BountyCreateViewModel(); bountyCreateViewModel.Bounty = this.db.Bounties.Find(id); this.characterAddEditViewModel.Character = this.db.Characters.Find(bountyCreateViewModel.Bounty.PlacedOnId); var viewModel = new BountyCreateViewModel { Bounty = bountyCreateViewModel.Bounty, Character = this.characterAddEditViewModel.Character, SelectedCharacter = bountyCreateViewModel.Bounty.PlacedById, }; return View("Edit", viewModel); } else { return RedirectToAction("Dashboard", "Home"); } }
public ActionResult Create(Character character) { this.characterAddEditViewModel.Character = this.db.Characters.Find(character.Id); ModelState["Name"].Errors.Clear(); var viewModel = new BountyCreateViewModel { Character = this.characterAddEditViewModel.Character }; return View(viewModel); }