private Campaigns.Model.Character CreateCharacter(CreateCharacterViewModel viewModel) { if (null == viewModel) { return(_rules.CreateCharacter("Unnamed", "")); } var standardAllocations = _rules.GetAttributesByCategory("abilities") .Where(a => a.IsStandard) .ToList() .Select(a => new AttributeAllocation { Attribute = a, Value = 8 }); var characterAllocations = new[] { new AttributeAllocation { Attribute = _rules.GetAttributeById(viewModel.RaceId) }, new AttributeAllocation { Attribute = _rules.GetAttributeById(viewModel.InitialClassId), Value = viewModel.Level }, }; var allocations = standardAllocations.Concat(characterAllocations); var newCharacter = _rules.CreateCharacter(viewModel.Name, viewModel.Description, allocations); return(newCharacter); }
public async Task <IActionResult> Edit(int id, CreateCharacterViewModel viewModel) { if (id != viewModel.Character.CharacterID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(viewModel.Character); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CharacterExists(viewModel.Character.CharacterID)) { return(NotFound()); } else { return(Redirect("~/Views/Shared/Error.cshtml")); } } return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
// Chreate character public IActionResult CreateCharacter() { var model = new CreateCharacterViewModel(); model.FillRaceList(); return(View(model)); }
public ActionResult GetRolls(Character character) { var model = new CreateCharacterViewModel(); model.Character = character; return(View(model)); }
public IActionResult Create() { CreateCharacterViewModel viewModel = new CreateCharacterViewModel(); viewModel.Character = new Character(); viewModel.CharacterClasses = new SelectList(_context.CharacterClasses, "CharacterClassID", "CharacterClassName"); viewModel.Players = new SelectList(_context.Players, "PlayerID", "Name"); return(View(viewModel)); }
public void CCVMPass() { var CCVM = new CreateCharacterViewModel() { Character = new Character() }; Assert.NotNull(CCVM.Character); }
public IActionResult CreateCharacter(CreateCharacterViewModel character) { if (ModelState.IsValid) { // TODO, store character link to User // Data is currently working. } throw new NotImplementedException(); }
public async Task <IActionResult> CreateCharacter(CreateCharacterViewModel characterViewModel) { var character = Mapper.Map <Character>(characterViewModel); character = _characterService.Add(character); await _dbContext.SaveChangesAsync(); await _cachingService.RemoveAsync($"{nameof(Character)}s"); return(Created("characters", character.Id)); }
public ActionResult Create(CreateCharacterViewModel charModel) { try { TempData["classId"] = charModel.Character.ClassID; return(RedirectToAction(nameof(Create2), "Character", charModel.Character)); } catch { return(View()); } }
public async Task <IActionResult> CreateCharacter() { var charactersQuantityInAccount = await _accountService.GetCharactersQuantity(User.Identity.Name); if (charactersQuantityInAccount >= 20) { return(RedirectToAction(nameof(Index), nameof(AccountController))); } var model = new CreateCharacterViewModel() { AllowedVocations = _characterService.GetVocationsOnCreate() }; return(View(model)); }
// GET: Characters/Create public IActionResult Create() { var CCMV = new CreateCharacterViewModel(); CCMV.Character = new Character(); var characterRace = _context.Race; var characterBackgrounds = _context.Background; var characterClass = _context.CharacterClass; List <SelectListItem> RaceSelectListItems = new List <SelectListItem>(); List <SelectListItem> BackgroundSelectListItem = new List <SelectListItem>(); List <SelectListItem> ClassSelectListItem = new List <SelectListItem>(); foreach (var race in characterRace) { SelectListItem li = new SelectListItem { Value = race.RaceId.ToString(), Text = race.RaceType }; RaceSelectListItems.Add(li); } foreach (var background in characterBackgrounds) { SelectListItem li = new SelectListItem { Value = background.BackgroundId.ToString(), Text = background.description }; BackgroundSelectListItem.Add(li); } foreach (var CharacterClass in characterClass) { SelectListItem li = new SelectListItem { Value = CharacterClass.CharacterClassId.ToString(), Text = CharacterClass.ClassName }; ClassSelectListItem.Add(li); } CCMV.CharacterClass = ClassSelectListItem; CCMV.Backgrounds = BackgroundSelectListItem; CCMV.Races = RaceSelectListItems; ViewData["UserId"] = new SelectList(_context.ApplicationUser, "Id", "Id"); return(View(CCMV)); }
// GET: Character/Create2Get public async Task <ActionResult> Create2(Character character) { var charModel = new CreateCharacterViewModel(); charModel.Character = character; charModel.Skills = new List <Skill>(); charModel.Classes = new List <Class>(); charModel.Races = new List <Race>(); using (var httpClient = new HttpClient()) { HttpRequestMessage request = CreateRequestToService(HttpMethod.Get, Configuration["ServiceEndpoints:AccountCharacter"] + "/Class/" + character.ClassID.ToString()); HttpRequestMessage request2 = CreateRequestToService(HttpMethod.Get, Configuration["ServiceEndpoints:AccountClass"]); HttpRequestMessage request3 = CreateRequestToService(HttpMethod.Get, Configuration["ServiceEndpoints:AccountRace"]); var Response = await httpClient.SendAsync(request); var Response1 = await httpClient.SendAsync(request2); var Response2 = await httpClient.SendAsync(request3); if (Response.IsSuccessStatusCode && Response1.IsSuccessStatusCode) { if (Response.IsSuccessStatusCode) { var jsonString = await Response.Content.ReadAsStringAsync(); var jsonString1 = await Response1.Content.ReadAsStringAsync(); var jsonString2 = await Response2.Content.ReadAsStringAsync(); charModel.Skills = JsonConvert.DeserializeObject <List <Skill> >(jsonString); charModel.Classes = JsonConvert.DeserializeObject <List <Class> >(jsonString1); charModel.Races = JsonConvert.DeserializeObject <List <Race> >(jsonString2); } } } return(View(charModel)); }
public async Task <IActionResult> Create(CreateCharacterViewModel viewModel) { if (ModelState.IsValid) { try { _context.Add(viewModel.Character); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception) { return(Redirect("~/Views/Shared/Error.cshtml")); } } viewModel.CharacterClasses = new SelectList(_context.CharacterClasses, "CharacterClassID", "CharacterClassName"); viewModel.Players = new SelectList(_context.Players, "PlayerID", "Name"); return(View(viewModel)); }
public async Task <IActionResult> Create(CreateCharacterViewModel model) { ModelState.Remove("UserId"); ModelState.Remove("User"); ModelState.Remove("Races"); ModelState.Remove("Feats"); ModelState.Remove("Backgrounds"); ModelState.Remove("CharacterClass"); var user = await GetCurrentUserAsync(); if (ModelState.IsValid) { model.Character.User = user; model.Character.UserId = user.Id; _context.Add(model.Character); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(_context.ApplicationUser, "Id", "Id", model.Character.UserId); return(View(model)); }
public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } Character character = await _context.Characters.FindAsync(id); if (character == null) { return(NotFound()); } CreateCharacterViewModel viewModel = new CreateCharacterViewModel { Character = character, Players = new SelectList(_context.Players, "PlayerID", "Name"), CharacterClasses = new SelectList(_context.CharacterClasses, "CharacterClassID", "CharacterClassName") }; return(View(viewModel)); }
public async Task <IActionResult> Delete(int?id) { CreateCharacterViewModel viewModel = new CreateCharacterViewModel(); viewModel.Character = await _context.Characters .Include(c => c.Player) .Include(c => c.CharacterClass) .FirstOrDefaultAsync(m => m.CharacterID == id); if (id == null) { return(NotFound()); } if (viewModel.Character == null) { return(NotFound()); } return(View(viewModel)); }
public async Task <IActionResult> CreateCharacter(CreateCharacterViewModel model) { var charactersQuantityInAccount = await _accountService.GetCharactersQuantity(User.Identity.Name); if (charactersQuantityInAccount >= 20) { return(RedirectToAction(nameof(Index), nameof(AccountController))); } if (ModelState.IsValid) { var dto = Mapper <CreateCharacterViewModel, CreateCharacterDTO>(model); try { await _characterService.CreateNewCharacter(dto, User.Identity.Name); LogInformation($"New Character Created. " + $"Account: {User.Identity.Name}, " + $"Character: {dto.Name}"); return(RedirectToAction(nameof(Index), nameof(AccountController))); } catch (CharacterAlreadyRegisteredException) { AddModelErrors(_localizer["CharacterAlreadyRegistered"]); } catch (Exception ex) { LogError(ex, nameof(AccountController), nameof(CreateCharacter)); AddModelErrors(_localizer["UnknownErrorContactAnAdmin"]); } } model.AllowedVocations = _characterService.GetVocationsOnCreate(); return(View(model)); }
// GET: Character/Create public async Task <ActionResult> Create() { var model = new CreateCharacterViewModel(); model.Character = new Character(); model.Character.CampaignID = (int)TempData.Peek("campaignId"); model.Character.Username = (string)TempData.Peek("username"); using (var httpClient = new HttpClient()) { HttpRequestMessage request = CreateRequestToService(HttpMethod.Get, Configuration["ServiceEndpoints:AccountRace"]); var Response = await httpClient.SendAsync(request); if (Response.IsSuccessStatusCode) { var jsonString = await Response.Content.ReadAsStringAsync(); model.Races = JsonConvert.DeserializeObject <List <Race> >(jsonString); } HttpRequestMessage request2 = CreateRequestToService(HttpMethod.Get, Configuration["ServiceEndpoints:AccountClass"]); var Response2 = await httpClient.SendAsync(request2); if (Response.IsSuccessStatusCode) { var jsonString = await Response2.Content.ReadAsStringAsync(); model.Classes = JsonConvert.DeserializeObject <List <Class> >(jsonString); } } return(View(model)); }
public async Task <ActionResult> Create2(CreateCharacterViewModel charModel) { try { using (var httpClient = new HttpClient()) { HttpRequestMessage request = CreateRequestToService(HttpMethod.Post, Configuration["ServiceEndpoints:AccountCharacter"] + "/Buffer", charModel.Character); var Response = await httpClient.SendAsync(request); //if (Response.IsSuccessStatusCode) //{ // var jsonString = await Response.Content.ReadAsStringAsync(); // charModel.Character = JsonConvert.DeserializeObject<Character>(jsonString); //} } return(Redirect("http://localhost:4200/rolls")); } catch { return(View()); } }
public CreateCharacterWindow(CreateCharacterViewModel context) { InitializeComponent(); DataContext = context; }
public CreateCharacterPage(ClientViewModel frame, LoggedClient loggedClient, LoginSessionClient loginSessionNetworkClient) { InitializeComponent(); DataContext = new CreateCharacterViewModel(frame, loggedClient, loginSessionNetworkClient); }