public static JobViewModel CreateViewModel(Job job) { var model = new JobViewModel(); model.Position = job.Position; model.Description = job.Description; model.Employer = job.Employer; model.StartDate = job.StartDate; model.EndDate = job.EndDate; return model; }
public ActionResult CreateJob([DataSourceRequest] DataSourceRequest dsRequest, JobViewModel jobViewModel, int userId) { if (ModelState.IsValid) { var job = new Job(); var user = db.UserProfiles.Find(userId); job.UserId = user.UserId; job.UserProfile = user; job.Employer = jobViewModel.Employer; job.Position = jobViewModel.Position; job.Description = jobViewModel.Description; job.StartDate = jobViewModel.StartDate; job.EndDate = jobViewModel.EndDate; db.Jobs.Add(job); db.SaveChanges(); jobViewModel.Id = job.Id; } return Json(new[] { jobViewModel }.ToDataSourceResult(dsRequest, ModelState)); }