Ejemplo n.º 1
0
        //[Authorize(Policy = "EditRolePolicy")]
        public async Task <IActionResult> Edit(string Id)
        {
            int decryptedId;
            int y;

            if (int.TryParse(Id, out y))
            {
                decryptedId = y;
            }
            else
            {
                decryptedId = Convert.ToInt32(protector.Unprotect(Id));
            }
            if (decryptedId < 1)
            {
                return(RedirectToAction("Index"));
            }
            Level level = await levelService.GetLevel(decryptedId);

            LevelEditViewModel model = new LevelEditViewModel
            {
                Id               = Id,
                Name             = level.Name,
                DateCreated      = level.DateCreated,
                Description      = level.Description,
                DateModified     = level.DateModified,
                LevelEncryptedId = Id
            };

            return(View(model));
        }
        public async Task <IActionResult> Create(LevelEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var level = new EmployeeLevelModel
            {
                LevelName = model.LevelName,
                LevelCode = model.LevelCode
            };

            await _levelService.AddAsync(level);

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Edit(int id)
        {
            var level = await _levelService.GetByIdAsync(id);

            if (level == null)
            {
                return(NotFound());
            }

            var editModel = new LevelEditViewModel
            {
                LevelId   = level.LevelId,
                LevelName = level.LevelName,
                LevelCode = level.LevelCode
            };

            return(View(editModel));
        }
Ejemplo n.º 4
0
        public LevelUpViewModel(Dictionary <KeyValuePair <Guid, string>, int> classesMap, int level)
        {
            _classesMap = classesMap;

            LevelModel levelModel = new LevelModel();

            levelModel.Level = level;
            if (_classesMap.Any())
            {
                levelModel.Class = _compendium.Classes.FirstOrDefault(x => _classesMap.Keys.Any(y => y.Key == x.Id));
            }
            if (levelModel.Class == null)
            {
                levelModel.Class = _compendium.Classes.FirstOrDefault();
            }
            levelModel.HitDieResult = levelModel.Class != null ? levelModel.Class.HitDie : 0;

            _levelEditViewModel = new LevelEditViewModel(levelModel);
            _levelEditViewModel.ClassChanged += _levelEditViewModel_ClassChanged;

            SetLevelOfClass();
        }
Ejemplo n.º 5
0
        //[Authorize(Policy = "EditRolePolicy")]
        public async Task <IActionResult> Edit(LevelEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                int decryptedId;
                int y;
                if (int.TryParse(model.Id, out y))
                {
                    decryptedId = y;
                }
                else
                {
                    decryptedId = Convert.ToInt32(protector.Unprotect(model.Id));
                }

                Level level = await levelService.GetLevel(decryptedId);

                level.Name         = model.Name;
                level.Description  = model.Description;
                level.DateCreated  = model.DateCreated;
                level.DateModified = model.DateModified;

                try
                {
                    await levelService.UpdateLevel(level);

                    return(RedirectToAction("Index"));
                }
                catch (Exception)
                {
                    ModelState.AddModelError(string.Empty, " Ensure and level Id is Valid");
                }

                return(View(model));
            }
            return(View(model));
        }