Exemple #1
0
        public async Task <IActionResult> EditUnitType(int unitTypeId)
        {
            var model = new EditUnitTypeView();

            model.UnitType = await _unitsService.GetUnitTypeByIdAsync(unitTypeId);

            var states = new List <CustomState>();

            states.Add(new CustomState
            {
                Name = "Standard Actions"
            });
            states.AddRange(await _customStateService.GetAllActiveUnitStatesForDepartmentAsync(DepartmentId));
            model.States             = states;
            model.UnitCustomStatesId = model.UnitType.CustomStatesId.GetValueOrDefault();

            return(View(model));
        }
Exemple #2
0
        public async Task <IActionResult> EditUnitType(EditUnitTypeView model, CancellationToken cancellationToken)
        {
            var states = new List <CustomState>();

            states.Add(new CustomState
            {
                Name = "Standard Actions"
            });
            states.AddRange(await _customStateService.GetAllActiveUnitStatesForDepartmentAsync(DepartmentId));
            model.States = states;

            var unitTypes = await _unitsService.GetUnitTypesForDepartmentAsync(DepartmentId);

            if (unitTypes.Any(x => x.Type == model.UnitType.Type && x.UnitTypeId != model.UnitType.UnitTypeId))
            {
                ModelState.AddModelError("Type", string.Format("A Unit Type of ({0}) already exists.", model.UnitType.Type));
            }

            if (ModelState.IsValid)
            {
                var unitType = await _unitsService.GetUnitTypeByIdAsync(model.UnitType.UnitTypeId);

                unitType.Type = model.UnitType.Type;

                if (model.UnitCustomStatesId != 0)
                {
                    unitType.CustomStatesId = model.UnitCustomStatesId;
                }
                else
                {
                    unitType.CustomStatesId = null;
                }

                await _unitsService.SaveUnitTypeAsync(unitType, cancellationToken);

                return(RedirectToAction("Types", "Department", new { Area = "User" }));
            }

            return(View(model));
        }