public ActionResult DeleteJob([DataSourceRequest] DataSourceRequest dsRequest, JobViewModel jobViewModel)
        {
            var jobModel = db.Jobs.SingleOrDefault(job => job.Id == jobViewModel.Id);
            if (jobModel != null && ModelState.IsValid)
            {
                db.Jobs.Remove(jobModel);
                db.SaveChanges();
            }

            return Json(ModelState.ToDataSourceResult());
        }
        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;
        }
Пример #3
0
        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 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 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));
        }
        public ActionResult UpdateJob([DataSourceRequest] DataSourceRequest dsRequest, JobViewModel jobViewModel)
        {
            var jobModel = db.Jobs.SingleOrDefault(job => job.Id == jobViewModel.Id);
            if (jobModel != null && ModelState.IsValid)
            {
                jobModel.Employer = jobViewModel.Employer;
                jobModel.Position = jobViewModel.Position;
                jobModel.Description = jobViewModel.Description;
                jobModel.StartDate = jobViewModel.StartDate;
                jobModel.EndDate = jobViewModel.EndDate;

                db.Entry<Job>(jobModel).State = EntityState.Modified;
                db.SaveChanges();
            }

            return Json(ModelState.ToDataSourceResult());
        }