Пример #1
0
        public async Task <IActionResult> Create(SkillEditModel model)
        {
            if (ModelState.IsValid)
            {
                if (!User.IsUserType(UserType.SiteAdmin))
                {
                    model.OwningOrganizationId = User.GetOrganizationId();
                }
                await _mediator.SendAsync(new SkillEditCommandAsync { Skill = model });

                return(RedirectToAction("Index", new { area = "Admin" }));
            }

            if (User.IsUserType(UserType.SiteAdmin))
            {
                model.ParentSelection = await _mediator.SendAsync(new SkillListQueryAsync());

                model.OrganizationSelection = await _mediator.SendAsync(new OrganizationSelectListQueryAsync());
            }
            else
            {
                var organizationId = User.GetOrganizationId();
                if (!organizationId.HasValue)
                {
                    return(new HttpUnauthorizedResult()); // Edge case of user having Org Admin claim but not Org Id claim
                }
                model.ParentSelection = await _mediator.SendAsync(new SkillListQueryAsync { OrganizationId = organizationId.Value });
            }

            return(View("Edit", model));
        }
Пример #2
0
        private static Mock <IMediator> MockMediatorSkillEditQuery(out SkillController controller, SkillEditModel model = null)
        {
            if (model == null)
            {
                model = new SkillEditModel {
                    Id = 1, Name = "Name", Description = "Description"
                }
            }
            ;

            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(mock => mock.SendAsync(It.IsAny <SkillEditQueryAsync>())).Returns(() => Task.FromResult(model)).Verifiable();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny <SkillListQueryAsync>())).Returns(() => Task.FromResult(SummaryListItems()))
            .Verifiable();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny <OrganizationSelectListQueryAsync>()))
            .Returns(() => Task.FromResult <IEnumerable <SelectListItem> >(new List <SelectListItem> {
                new SelectListItem {
                    Text = "Item 1", Value = "1"
                }
            }))
            .Verifiable();
            controller = new SkillController(mockMediator.Object);
            return(mockMediator);
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id)
        {
            SkillEditModel model = await _mediator.SendAsync(new SkillEditQueryAsync { Id = id });

            if (model == null)
            {
                return(HttpNotFound());
            }

            if (User.IsUserType(UserType.SiteAdmin))
            {
                model.ParentSelection = await _mediator.SendAsync(new SkillListQueryAsync());

                model.OrganizationSelection = await _mediator.SendAsync(new OrganizationSelectListQueryAsync());
            }
            else
            {
                var organizationId = User.GetOrganizationId();

                // security check to ensure the skill belongs to the same org as the org admin
                if (!organizationId.HasValue || model.OwningOrganizationId != organizationId)
                {
                    return(new HttpUnauthorizedResult());
                }

                model.ParentSelection = await _mediator.SendAsync(new SkillListQueryAsync { OrganizationId = organizationId.Value });
            }

            model.ParentSelection = model.ParentSelection.Where(p => p.Id != model.Id); // remove self from the parent select list

            return(View("Edit", model));
        }
Пример #4
0
        public async Task <IActionResult> Edit(SkillEditModel model)
        {
            if (ModelState.IsValid)
            {
                await _mediator.SendAsync(new SkillEditCommandAsync { Skill = model });

                return(RedirectToAction(nameof(Index), new { area = "Admin" }));
            }

            if (User.IsUserType(UserType.SiteAdmin))
            {
                model.ParentSelection = await _mediator.SendAsync(new SkillListQueryAsync());

                model.OrganizationSelection = await _mediator.SendAsync(new OrganizationSelectListQueryAsync());
            }
            else
            {
                var organizationId = User.GetOrganizationId();
                if (!organizationId.HasValue)
                {
                    return(new UnauthorizedResult()); // Edge case of user having Org Admin claim but not Org Id claim
                }

                model.ParentSelection = await _mediator.SendAsync(new SkillListQueryAsync { OrganizationId = organizationId.Value });
            }

            model.ParentSelection = model.ParentSelection.Where(p => p.Id != model.Id); // remove self from the parent select list

            return(View(model));
        }
Пример #5
0
 public EditSkill(SkillEditModel model)
 {
     BindingContext   = Model = model;
     Model.Navigation = Navigation;
     InitializeComponent();
     Model.TrackChanges = true;
 }
        public async Task AddNewSkill()
        {
            // Arrange
            var handler  = new SkillEditCommandHandlerAsync(Context);
            var newSkill = new SkillEditModel {
                Name = "New", Description = "Desc"
            };

            // Act
            var result = await handler.Handle(new SkillEditCommandAsync { Skill = newSkill });

            // Assert
            Assert.Equal(8, Context.Skills.Count());
            Assert.Equal(8, result);
        }
        public async Task UpdatingExistingSkill()
        {
            // Arrange
            var handler  = new SkillEditCommandHandlerAsync(Context);
            var newSkill = new SkillEditModel {
                Id = 2, Name = "New", Description = "Desc", OwningOrganizationId = 1
            };

            // Act
            var result = await handler.Handle(new SkillEditCommandAsync { Skill = newSkill });

            var savedSkill = Context.Skills.SingleOrDefault(s => s.Id == 2);

            // Assert
            Assert.Equal(7, Context.Skills.Count());
            Assert.Equal(2, result);
            Assert.Equal("New", savedSkill.Name);
        }
Пример #8
0
        public async Task <IActionResult> Create()
        {
            var organizationId = User.GetOrganizationId();

            if (!User.IsUserType(UserType.SiteAdmin) && !organizationId.HasValue)
            {
                return(new HttpUnauthorizedResult()); // Edge case of user having Org Admin claim but not Org Id claim
            }
            var model = new SkillEditModel();

            if (User.IsUserType(UserType.SiteAdmin))
            {
                model.ParentSelection = await _mediator.SendAsync(new SkillListQueryAsync());

                model.OrganizationSelection = await _mediator.SendAsync(new OrganizationSelectListQueryAsync());
            }
            else
            {
                model.ParentSelection = await _mediator.SendAsync(new SkillListQueryAsync { OrganizationId = organizationId.Value });
            }

            return(View("Edit", model));
        }
Пример #9
0
 public int Save(SkillEditModel model) => MappingSave(_skillRepository, model);