Пример #1
0
        public async Task<ActionResult> CharactersPanel()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Login", "Account", new { returnUrl = Url });
            }

            var user = ApplicationDb.Users.Find(User.Identity.GetUserId());
            if (user == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.NotFound);
            }

            // Wyszukiwanie postaci po ID użytkownika obecnie zalogowanego
            CharacterDbModel[] characterDbModel = await 
                ApplicationDb.Characters.Where(c => c.UserID == user.Id).ToArrayAsync();

            CharacterViewModel[] model = new CharacterViewModel[characterDbModel.Length];
            int iterator = 0;
            foreach (CharacterDbModel characterDb in characterDbModel)
            {
                model[iterator] = new CharacterViewModel(new Character(characterDb));
                iterator++;
            }

            return View(model);
        }
Пример #2
0
 public ActionResult Create()
 {
     // Pobranie listy kart graczy
     ViewBag.AvailableCharts = db.CharacterCharts.ToList();
     CharacterViewModel model = new CharacterViewModel(new Character());
     return View(model);
 }
Пример #3
0
 // GET: Character/Details/[CharacterID]
 public ActionResult Details(string id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     CharacterDbModel character = db.Characters.Where(c => c.CharacterID == id).First();
     if (character == null)
     {
         return HttpNotFound();
     }
     CharacterViewModel model = new CharacterViewModel(new Character(character));
     return View(model);
 }
Пример #4
0
        public async Task<ActionResult> Create(CharacterViewModel Model)
        {
            if (ModelState.IsValid)
            {
                var user = db.Users.Find(User.Identity.GetUserId());

                Character characterModel = 
                    new Character(
                        Request.Form,
                        Request.Files,
                        user);

                CharacterDbModel dbModel = 
                    new CharacterDbModel(
                        characterModel,
                        user);

                db.Characters.Add(dbModel);
                await db.SaveChangesAsync();
                return RedirectToAction("Index");
            }

            return View(Model);
        }
Пример #5
0
        public ActionResult GetForm(string id)
        {
            if (id != null &&
                db.CharacterCharts.Where(c => c.ChartID == id).Count() > 0)
            {
                CharacterViewModel model = new CharacterViewModel(
                    new Character(
                        new CharacterChart(id),
                        db.Users.Find(User.Identity.GetUserId())
                        ));

                return View(model);
            }
            return new HttpStatusCodeResult(HttpStatusCode.NotFound);
        }