Beispiel #1
0
        public async Task <ActionResult> Update(int id)
        {
            ScopeUpdateModel model           = new ScopeUpdateModel();
            GetScopeByIdDto  getScopeByIdDto = await Mediator.Send(new GetScopeByIdQuery
            {
                Id = id
            });

            if (getScopeByIdDto != null && getScopeByIdDto.Id > 0)
            {
                model = getScopeByIdDto.ToScopeUpdateModel();
                List <GetAllScopeClaimsDto> scopeClaims = await Mediator.Send(new GetAllScopeClaimsQuery());

                model.AvailableClaims = scopeClaims.Select(scopeClaim => new SelectListItem
                {
                    Selected = true,
                    Value    = scopeClaim.Id.ToString(),
                    Text     = scopeClaim.Description
                }).ToList();

                return(View(model));
            }

            return(RedirectToAction("List"));
        }
Beispiel #2
0
        public async Task <ActionResult> Update(ScopeUpdateModel model)
        {
            if (ModelState.IsValid)
            {
                Application.Scopes.Commands.UpdateScopeCommand updateScopeCommand = model.ToUpdateScopeCommand();
                updateScopeCommand.CreatedBy = User.Identity.Name;
                updateScopeCommand.CreatedOn = DateTime.Now;

                int result = await Mediator.Send(updateScopeCommand);

                if (result > 0)
                {
                    return(View("List"));
                }
                else
                {
                    ModelState.AddModelError("", "Update Scope thất bại");
                }
            }

            List <GetAllScopeClaimsDto> scopeClaims = await Mediator.Send(new GetAllScopeClaimsQuery());

            model.AvailableClaims = scopeClaims.Select(scopeClaim => new SelectListItem
            {
                Value = scopeClaim.Id.ToString(),
                Text  = scopeClaim.Description
            }).ToList();

            return(View(model));
        }
 public static UpdateScopeCommand ToUpdateScopeCommand(this ScopeUpdateModel model)
 {
     return(model.MapTo <ScopeUpdateModel, UpdateScopeCommand>());
 }