示例#1
0
        public async Task <SkillEditViewModel> EditDeleteForm(int id, string userName)
        {
            var skill = await this.skillRepo.All().SingleOrDefaultAsync(s => s.Id == id);

            var user = await this.userRepo.All().SingleOrDefaultAsync(u => u.ResumeId == skill.ResumeId);

            var currentUser = user.UserName;

            if (userName != currentUser)
            {
                return(null);
            }

            SkillEditViewModel model = null;

            if (skill != null)
            {
                model = new SkillEditViewModel
                {
                    Id       = skill.Id,
                    Name     = skill.Name,
                    ResumeId = skill.ResumeId
                };
            }

            return(model);
        }
示例#2
0
        public async Task <IActionResult> Create(SkillEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!User.IsUserType(UserType.SiteAdmin))
                {
                    model.OwningOrganizationId = User.GetOrganizationId();
                }

                await _mediator.SendAsync(new SkillEditCommand { Skill = model });

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

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

                model.OrganizationSelection = await _mediator.SendAsync(new OrganizationSelectListQuery());
            }
            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 SkillListQuery { OrganizationId = organizationId.Value });
            }

            return(View("Edit", model));
        }
示例#3
0
        public async Task Update(SkillEditViewModel model)
        {
            if (this.resumeId == null)
            {
                throw new InvalidOperationException($"Resume id is null.");
            }

            var skill = new Skill
            {
                Id       = model.Id,
                ResumeId = this.resumeId.Value,
                Name     = this.sanitizer.Sanitize(model.Name),
            };

            this.skillRepo.Update(skill);

            try
            {
                await this.skillRepo.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(e.Message);
            }
        }
示例#4
0
        public async Task <IActionResult> Edit(SkillEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                await _mediator.SendAsync(new SkillEditCommand { Skill = model });

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

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

                model.OrganizationSelection = await _mediator.SendAsync(new OrganizationSelectListQuery());
            }
            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 SkillListQuery { 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
        private static Mock <IMediator> MockMediatorSkillEditQuery(out SkillController controller, SkillEditViewModel model = null)
        {
            if (model == null)
            {
                model = new SkillEditViewModel {
                    Id = 1, Name = "Name", Description = "Description"
                }
            }
            ;

            var mockMediator = new Mock <IMediator>();

            mockMediator.Setup(mock => mock.SendAsync(It.IsAny <SkillEditQuery>())).Returns(() => Task.FromResult(model)).Verifiable();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny <SkillListQuery>())).Returns(() => Task.FromResult(SummaryListItems()))
            .Verifiable();
            mockMediator.Setup(mock => mock.SendAsync(It.IsAny <OrganizationSelectListQuery>()))
            .Returns(() => Task.FromResult <IEnumerable <SelectListItem> >(new List <SelectListItem> {
                new SelectListItem {
                    Text = "Item 1", Value = "1"
                }
            }))
            .Verifiable();
            controller = new SkillController(mockMediator.Object);
            return(mockMediator);
        }
示例#6
0
        public ResultViewModel <SkillEditViewModel> Update(SkillEditViewModel Skill)
        {
            ResultViewModel <SkillEditViewModel> result
                = new ResultViewModel <SkillEditViewModel>();

            try
            {
                if (!ModelState.IsValid)
                {
                    result.Message = "In Valid Model State";
                }
                else
                {
                    SkillEditViewModel selectedSkill
                        = skillService.Update(Skill);
                    result.Successed = true;
                    result.Data      = selectedSkill;
                }
            }
            catch (Exception ex)
            {
                result.Successed = false;
                result.Message   = "Semething Went Wrong";
            }
            return(result);
        }
示例#7
0
        public async Task <IActionResult> Post([FromBody] SkillEditViewModel vm)
        {
            var skillSet = dbContext.Set <Skill>();
            var existing = await skillSet.FirstOrDefaultAsync(s => s.Name == vm.Name);

            if (existing != null)
            {
                ModelState.AddModelError(nameof(SkillEditViewModel.Name), "A skill with the same name already exists.");
            }

            if (ModelState.IsValid)
            {
                var skill = new Skill();
                vm.ApplyTo(skill);

                skillSet.Add(skill);
                await dbContext.SaveChangesAsync();

                return(CreatedAtRoute("GetSkillById", new { id = skill.Id }, new SkillListViewModel(skill)));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public async Task <IActionResult> Create()
        {
            var viewModel = new SkillEditViewModel
            {
                SkillGroups = await _employeeDetailService.GetSkillGroups(),
                SkillTypes  = await _employeeDetailService.GetSkillTypes()
            };

            return(View(viewModel));
        }
示例#9
0
        public SkillEdit()
        {
            InitializeComponent();
            SkillEditViewModel vm = new SkillEditViewModel();

            this.DataContext = vm;
            if (vm.CloseAction == null)
            {
                vm.CloseAction = this.Close;
            }
        }
        public async Task AddNewSkill()
        {
            // Arrange
            var handler  = new SkillEditCommandHandler(Context);
            var newSkill = new SkillEditViewModel {
                Name = "New", Description = "Desc"
            };

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

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

            // Act
            var result = await handler.Handle(new SkillEditCommand { 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);
        }
示例#12
0
        public async Task <IActionResult> Edit(SkillEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                await this.skillService.Update(model);
            }
            catch (Exception e)
            {
                this.logger.LogDebug(e, $"An exception happened for user {this.userName}");
                return(this.BadRequest());
            }

            return(this.Redirect(Url.RouteUrl(new { controller = "Resume", action = "Display" }) + $"#{model.Id}"));
        }
示例#13
0
        public async Task Delete(SkillEditViewModel model)
        {
            if (model == null)
            {
                throw new NullReferenceException("Invalid data");
            }

            var skill = await this.skillRepo.GetByIdAsync(model.Id);

            try
            {
                this.skillRepo.Delete(skill);
                await this.skillRepo.SaveChangesAsync();
            }
            catch (Exception e)
            {
                throw new InvalidOperationException($"Unable to delete skill {model.Id} id.", e);
            }
        }
        public async Task <IActionResult> Create(SkillEditViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var skillGroup = new SkillModel
            {
                SkillGroupId     = viewModel.SkillGroupId,
                SkillTypeId      = viewModel.SkillTypeId,
                SkillName        = viewModel.SkillName,
                SkillDescription = viewModel.SkillDescription,
            };

            await _skillService.AddAsync(skillGroup);

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Edit(SkillEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var editModel = new SkillModel
            {
                SkillId          = model.SkillId,
                SkillGroupId     = model.SkillGroupId,
                SkillTypeId      = model.SkillTypeId,
                SkillName        = model.SkillName,
                SkillDescription = model.SkillDescription
            };

            await _skillService.UpdateAsync(editModel);

            return(RedirectToAction(nameof(Index)));
        }
示例#16
0
        public async Task <IActionResult> Put(int id, [FromBody] SkillEditViewModel vm)
        {
            var skill = await dbContext.Set <Skill>().FindAsync(id);

            if (skill == null)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                vm.ApplyTo(skill);

                await dbContext.SaveChangesAsync();

                return(AcceptedAtRoute("GetSkillById", new { id = skill.Id }, new SkillListViewModel(skill)));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public async Task <IActionResult> Edit(int id)
        {
            var skill = await _skillService.GetByIdAsync(id);

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

            var editModel = new SkillEditViewModel
            {
                SkillId          = skill.SkillId,
                SkillGroupId     = skill.SkillGroupId,
                SkillTypeId      = skill.SkillTypeId,
                SkillName        = skill.SkillName,
                SkillDescription = skill.SkillDescription,
                SkillGroups      = await _employeeDetailService.GetSkillGroups(),
                SkillTypes       = await _employeeDetailService.GetSkillTypes()
            };

            return(View(editModel));
        }
示例#18
0
        public async Task <IActionResult> Create()
        {
            var organizationId = User.GetOrganizationId();

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

            var model = new SkillEditViewModel();

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

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

            return(View("Edit", model));
        }