Пример #1
0
        /// <summary>
        /// Update Skill
        /// </summary>
        /// <param name="id"></param>
        /// <param name="skillRequestModel"></param>
        /// <returns></returns>
        public async Task <SkillViewModel> UpdateSkill(int id, SkillRequestModel skillRequestModel)
        {
            model.AppResult.Result  = false;
            model.SkillRequestModel = skillRequestModel;
            if (id <= 0)
            {
                model.AppResult.Message = "PersonId not exist!";
            }
            else if (skillRequestModel.TechnologyId.Count <= 0)
            {
                model.AppResult.Message = "TechnologyId not exist!";
            }
            else if (skillRequestModel.CategoryId <= 0)
            {
                model.AppResult.Message = "CategoryId not exist!";
            }
            else
            {
                PersonCategory personCategory = await _skillRepository.GetPersonCategoryAsync(id, null, null);

                if (personCategory == null)
                {
                    model.AppResult.Message = "Update failure, Skill not exists";
                }
                else
                {
                    var modelCategory = await _categoryRepository.FindAsync(skillRequestModel.CategoryId);

                    if (modelCategory == null)
                    {
                        model.AppResult.Message = "Update failure, Category not exists";
                    }
                    else
                    {
                        List <PersonTechnology> personTechnologies = new List <PersonTechnology>();
                        personTechnologies = await GetListPersonTechnology(skillRequestModel);

                        if (personTechnologies.Count > 0)
                        {
                            personCategory.CategoryId = skillRequestModel.CategoryId;
                            personCategory.CreatedBy  = WebAPI.Helpers.HttpContext.CurrentUser;
                            personCategory.UpdatedBy  = WebAPI.Helpers.HttpContext.CurrentUser;
                            await _skillRepository.DeletePersonTechnologyToUpdateAsync(personCategory);

                            await _skillRepository.InsertListPersonTechnologyAsync(personTechnologies);

                            if (id > 0 && skillRequestModel.PersonId > 0)
                            {
                                List <Category> listResult = new List <Category>();
                                modelCategory = await _skillRepository.GetSkillInsertAsync(id, skillRequestModel.PersonId);

                                if (modelCategory != null)
                                {
                                    model.AppResult.Result  = true;
                                    model.AppResult.Message = Constants.Constant.UPDATE_SUCCESS;
                                    listResult.Add(modelCategory);
                                    model.AppResult.DataResult = GetListSkillResource(listResult).FirstOrDefault();
                                }
                            }
                        }
                        else
                        {
                            model.AppResult.Message = "Update failure, Technology not exists";
                        }
                    }
                }
            }
            return(model);
        }