Exemple #1
0
        // GET: UserSkills/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var userSkill = await _bll.UserSkills.FindAsync(id);

            if (userSkill == null)
            {
                return(NotFound());
            }
            var vm = new UserSkillEditViewModel()
            {
                AppUserSelectList = new SelectList(await _bll.AppUsers.AllAsync(),
                                                   nameof(BLL.App.DTO.Identity.AppUser.Id),
                                                   nameof(BLL.App.DTO.Identity.AppUser.Id),
                                                   userSkill.AppUserId),
                SkillSelectList = new SelectList(await _bll.Skills.AllAsync(),
                                                 nameof(BLL.App.DTO.Skill.Id),
                                                 nameof(BLL.App.DTO.Skill.Id),
                                                 userSkill.SkillId),
            };

            return(View(vm));
        }
        public ResultViewModel <UserSkillEditViewModel> Update(UserSkillEditViewModel UserSkills)
        {
            ResultViewModel <UserSkillEditViewModel> result
                = new ResultViewModel <UserSkillEditViewModel>();

            try
            {
                if (!ModelState.IsValid)
                {
                    result.Message = "In Valid Model State";
                }
                else
                {
                    UserSkillEditViewModel selectedSkill = UserSkillService.Update(UserSkills);



                    result.Successed = true;
                    result.Data      = selectedSkill;
                }
            }
            catch (Exception ex)
            {
                result.Successed = false;
                result.Message   = "Semething Went Wrong";
            }
            return(result);
        }
Exemple #3
0
        public async Task <IActionResult> Edit(int id, UserSkillEditViewModel vm)
        {
            if (id != vm.UserSkill.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _bll.UserSkills.Update(vm.UserSkill);
                await _bll.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            vm.AppUserSelectList = new SelectList(await _bll.AppUsers.AllAsync(),
                                                  nameof(BLL.App.DTO.Identity.AppUser.Id),
                                                  nameof(BLL.App.DTO.Identity.AppUser.Id),
                                                  vm.UserSkill.AppUserId);
            vm.SkillSelectList = new SelectList(await _bll.Skills.AllAsync(),
                                                nameof(BLL.App.DTO.Skill.Id),
                                                nameof(BLL.App.DTO.Skill.Id),
                                                vm.UserSkill.SkillId);

            return(View(vm));
        }
        public ResultViewModel <UserSkillEditViewModel> Post(UserSkillEditViewModel UserSkill)
        {
            ResultViewModel <UserSkillEditViewModel> result
                = new ResultViewModel <UserSkillEditViewModel>();

            try
            {
                if (!ModelState.IsValid)
                {
                    result.Message = "In Valid Model State";
                }
                else if (UserSkillService.GetAll(UserSkill.UserID).Where(i => i.SkillID == UserSkill.SkillID).Count() > 0)
                {
                    result.Successed = false;
                    result.Message   = "Skill Already Exist";
                }
                else
                {
                    UserSkillEditViewModel selectedUserSkill
                        = UserSkillService.Add(UserSkill);

                    result.Successed = true;
                    result.Data      = selectedUserSkill;
                }
            }
            catch (Exception ex)
            {
                result.Successed = false;
                result.Message   = "Semething Went Wrong";
            }
            return(result);
        }