public static SkillViewModel CreateViewModel(Skill skill)
        {
            var model = new SkillViewModel();
            model.Id = skill.Id;
            model.Name = skill.Name;
            model.Endorsements = skill.Endorsements.Select(x => ProfileConnectionViewModel.CreateViewModel(x.Endorser));

            return model;
        }
Exemplo n.º 2
0
        public static SkillViewModel CreateViewModel(Skill skill)
        {
            var model = new SkillViewModel();

            model.Id           = skill.Id;
            model.Name         = skill.Name;
            model.Endorsements = skill.Endorsements.Select(x => ProfileConnectionViewModel.CreateViewModel(x.Endorser));

            return(model);
        }
        public ActionResult DeleteSkill([DataSourceRequest] DataSourceRequest dsRequest, SkillViewModel skillViewModel)
        {
            var skillModel = db.Skills.SingleOrDefault(skill => skill.Id == skillViewModel.Id);
            if (skillModel != null && ModelState.IsValid)
            {
                db.Skills.Remove(skillModel);
                db.SaveChanges();
            }

            return Json(ModelState.ToDataSourceResult());
        }
        public static ProfileViewModel CreateViewModel(UserProfile user, bool isIndex = false)
        {
            var model = new ProfileViewModel();

            model.Id         = user.UserId;
            model.Name       = string.Format("{0} {1}", user.FirstName, user.LastName);
            model.Email      = user.Email;
            model.Skills     = new List <SkillViewModel>();
            model.Jobs       = new List <JobViewModel>();
            model.Educations = new List <EducationViewModel>();
            model.APIKey     = user.APIKey;

            if (isIndex)
            {
                if (user.SkillVisibility == VisibilityState.Public)
                {
                    model.Skills = user.Skills.Select(s => SkillViewModel.CreateViewModel(s));
                }

                if (user.JobsVisibility == VisibilityState.Public)
                {
                    model.Jobs = user.Jobs.Select(j => JobViewModel.CreateViewModel(j));
                }

                if (user.EducationVisibility == VisibilityState.Public)
                {
                    model.Educations = user.Education.Select(e => EducationViewModel.CreateViewModel(e));
                }
            }
            else
            {
                model.APIKey = string.Empty;
            }

            model.Connections = user.Followers
                                .Where(e => e.Visibility == VisibilityState.Public)
                                .Select(e => ProfileConnectionViewModel.CreateViewModel(e));

            model.Requests = user.Requests.Select(r => new ProfileViewModel()
            {
                Name = r.FromUserName,
                Id   = r.FromUserId
            });

            return(model);
        }
        public ActionResult CreateSkill([DataSourceRequest] DataSourceRequest dsRequest, SkillViewModel skillViewModel)
        {
            if (ModelState.IsValid)
            {
                var skill = new Skill();
                var user = db.UserProfiles.Find(WebSecurity.CurrentUserId);

                skill.UserId = user.UserId;
                skill.UserProfile = user;
                skill.Name = skillViewModel.Name;
                db.Skills.Add(skill);
                db.SaveChanges();
                skillViewModel.Id = skill.Id;
            }

            return Json(new[] { skillViewModel }.ToDataSourceResult(dsRequest, ModelState));
        }
        public ActionResult UpdateSkill([DataSourceRequest] DataSourceRequest dsRequest, SkillViewModel skillViewModel)
        {
            var skillModel = db.Skills.SingleOrDefault(edu => edu.Id == skillViewModel.Id);
            if (skillModel != null && ModelState.IsValid)
            {
                skillModel.Name = skillViewModel.Name;

                db.Entry<Skill>(skillModel).State = EntityState.Modified;
                db.SaveChanges();
            }

            return Json(ModelState.ToDataSourceResult());
        }