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 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)); }