public ActionResult Edit(CharacterAddEditViewModel characterAddEditViewModel)
        {
            Character character = this.db.Characters.Find(characterAddEditViewModel.Character.Id);
            var accountId = this.account.GetLoggedInUserId();

            this.db.Entry(character).State = EntityState.Modified;

            if(this.character.IsCharacterOwner(accountId, character.Id) || this.character.UserId == Guid.Empty)
            {
                IQueryable<Character> existingCharacter = this.character.GetCharacterByName(characterAddEditViewModel.Character.Name, characterAddEditViewModel.SelectedShard, characterAddEditViewModel.SelectedFaction);

                if(existingCharacter.Count() != 0 && existingCharacter.Single().UserId != Guid.Empty && existingCharacter.Single().Id != characterAddEditViewModel.Character.Id)
                {
                    ModelState.AddModelError("Name", "A character with this information already exists.");
                }

                if(ModelState.IsValid)
                {
                    if(characterAddEditViewModel.Character.UserId == Guid.Empty)
                    {
                        character.UserId = accountId;
                    }

                    character.Name = characterAddEditViewModel.Character.Name;
                    character.ShardId = characterAddEditViewModel.SelectedShard;
                    character.FactionId = characterAddEditViewModel.SelectedFaction;
                    character.PlayerClassId = characterAddEditViewModel.SelectedPlayerClass;

                    if(characterAddEditViewModel.SelectedRace != null)
                    {
                        character.RaceId = characterAddEditViewModel.SelectedRace;
                    }

                    character.Motto = characterAddEditViewModel.Character.Motto;
                    character.Bio = characterAddEditViewModel.Character.Bio;

                    if(this.character.GetDefaultCharacterForAnAccount(accountId).Count() == 0)
                    {
                        character.IsPrimary = true;
                    }

                    character.AvatarId = this.avatar.GetAvatarBasedOnClass(characterAddEditViewModel.SelectedPlayerClass).Single().id;

                    this.db.SaveChanges();
                    return RedirectToAction("Dashboard", "Home");
                }
                else
                {
                    var viewModel = new CharacterAddEditViewModel
                    {
                        Character = characterAddEditViewModel.Character,
                        SelectedFaction = characterAddEditViewModel.Character.FactionId,
                        SelectedPlayerClass = characterAddEditViewModel.Character.PlayerClassId,
                        SelectedRace = characterAddEditViewModel.Character.RaceId,
                        SelectedShard = characterAddEditViewModel.Character.ShardId
                    };

                    return View("Edit", viewModel);
                }
            }
            else
            {
                return RedirectToAction("Dashboard", "Home");
            }
        }
        public ActionResult Create(CharacterAddEditViewModel characterAddEditViewModel)
        {
            var accountId = this.account.GetLoggedInUserId();

            IQueryable<Character> existingCharacter = this.character.GetCharacterByName(characterAddEditViewModel.Character.Name, characterAddEditViewModel.SelectedShard, characterAddEditViewModel.SelectedFaction);

            if(existingCharacter.Count() != 0 && existingCharacter.Single().UserId != Guid.Empty)
            {
                ModelState.AddModelError("Name", "A character with this information already exists.");
            }

            if(ModelState.IsValid)
            {
                if(existingCharacter.Count() != 0 && existingCharacter.Single().UserId == Guid.Empty)
                {
                    existingCharacter.Single().Bio = characterAddEditViewModel.Character.Bio;
                    existingCharacter.Single().Motto = characterAddEditViewModel.Character.Motto;
                    existingCharacter.Single().PlayerClassId = characterAddEditViewModel.SelectedPlayerClass;
                    existingCharacter.Single().RaceId = characterAddEditViewModel.SelectedRace;

                    this.Edit(existingCharacter.Single().Id);
                }
                else
                {
                    this.character.Id = Guid.NewGuid();
                    this.character.UserId = accountId;
                    this.character.Name = characterAddEditViewModel.Character.Name;
                    this.character.ShardId = characterAddEditViewModel.SelectedShard;
                    this.character.FactionId = characterAddEditViewModel.SelectedFaction;

                    if(characterAddEditViewModel.SelectedRace != null)
                    {
                        this.character.RaceId = characterAddEditViewModel.SelectedRace;
                    }

                    this.character.PlayerClassId = characterAddEditViewModel.SelectedPlayerClass;
                    this.character.Motto = characterAddEditViewModel.Character.Motto;
                    this.character.Bio = characterAddEditViewModel.Character.Bio;

                    if(characterAddEditViewModel.Character.IsPrimary.Equals(true))
                    {
                        if(this.character.GetDefaultCharacterForAnAccount(accountId).Count() != 0)
                        {
                            var defaultCharacterId = this.character.GetDefaultCharacterForAnAccount(accountId).Single().Id;

                            this.character.SetDefaultCharacterToFalse(defaultCharacterId);
                        }
                    }
                    else if(this.character.GetDefaultCharacterForAnAccount(accountId).Count() == 0)
                    {
                        this.character.IsPrimary = true;
                    }

                    this.character.AvatarId = this.avatar.GetAvatarBasedOnClass(characterAddEditViewModel.SelectedPlayerClass).Single().id;

                    this.db.Characters.Add(this.character);
                    this.db.SaveChanges();
                }

                return RedirectToAction("Dashboard", "Home");
            }
            else
            {
                return View(characterAddEditViewModel);
            }
        }
        public ActionResult Edit(Guid id)
        {
            if(this.character.IsCharacterOwner(this.account.GetLoggedInUserId(), id))
            {
                CharacterAddEditViewModel characterAddEditViewModel = new CharacterAddEditViewModel();

                characterAddEditViewModel.Character = this.db.Characters.Find(id);

                var viewModel = new CharacterAddEditViewModel
                {
                    Character = characterAddEditViewModel.Character,
                    SelectedFaction = characterAddEditViewModel.Character.FactionId,
                    SelectedPlayerClass = characterAddEditViewModel.Character.PlayerClassId,
                    SelectedRace = characterAddEditViewModel.Character.RaceId,
                    SelectedShard = characterAddEditViewModel.Character.ShardId
                };

                return View("Edit", viewModel);
            }
            else
            {
                return RedirectToAction("Dashboard", "Home");
            }
        }