Exemple #1
0
        public ActionResult Edit(string id, string summaryId, string activityId)
        {
            PersonViewModel person = new PersonViewModel();
              int pId = 0;
              if (Int32.TryParse(id, out  pId))
              {
            Person x = _personsRepository.Get(pId);
            person = new PersonViewModel
              {
            Id = x.Id.ToString(),
            FirstName = x.FirstName,
            LastName = x.LastName,
            Salary = x.Salary.ToString(),
            Age = ((DateTime.Now - x.BirthDate).Days / 365).ToString(),
            Job = x.Job,
            ActivityId = x.ActivityId.ToString(),
            SummaryId = x.SummaryId.ToString(),
            EducationLevel = x.EducationLevelId.ToString(),
            JobLevel = x.JobLevelId.ToString(),
            Summary = x.Summary.Title,
            Activity = x.Activity.Title
              };
              }
              else
              {
            person.SummaryId = summaryId;
            person.ActivityId = activityId;
              }

              ViewBag.EducationLevels = _personsRepository.EducationLevels().Select(x => new SelectListItem
            {
              Text = x.Title,
              Value = x.Id.ToString(),
              Selected = x.Id.ToString().Equals(person.EducationLevel)
            });
              ViewBag.JobLevels = _personsRepository.JobLevels().Select(x => new SelectListItem
              {
            Text = x.Title,
            Value = x.Id.ToString(),
            Selected = x.Id.ToString().Equals(person.JobLevel)
              });
              return View(person);
        }
Exemple #2
0
        public JsonResult Set(PersonViewModel person, ActivityViewModel activity, SummaryViewModel summary)
        {
            if (person != null)
            {
                if (person.Id == "null")
                {
                    //TODO: BirthDate
                    _perRep.Set(new Person
                    {
                        BirthDate = DateTime.Now.AddYears(-25),
                        FirstName = person.FirstName,
                        EducationLevelId = Int32.Parse(person.EducationLevel),
                        Job = person.Job,
                        JobLevelId =Int32.Parse(person.JobLevel),
                        LastName = person.LastName,
                        Salary = Decimal.Parse(person.Salary),
                        ActivityId = Int32.Parse(activity.Id),
                        SummaryId = Int32.Parse(summary.Id)

                    });
                }
                else
                {
                    Person selectedPerson = _perRep.List(new Summary { Id = Int32.Parse(summary.Id) }, new Activity { Id = Int32.Parse(activity.Id) })
                    .Single(x => x.Id.ToString() == person.Id);
                    _perRep.Set(selectedPerson);
                }
            }
            return this.Json(person ?? new PersonViewModel());
        }
Exemple #3
0
 public JsonResult Delete(PersonViewModel person)
 {
     _perRep.Delete(new Person { Id = Int32.Parse(person.Id) });
     return this.Json(null);
 }
Exemple #4
0
 public ActionResult Edit(PersonViewModel person)
 {
     if (ModelState.IsValid)
       {
     Person p = new Person
       {
     Id = Int32.Parse(person.Id ?? "0"),
     FirstName = person.FirstName,
     LastName = person.LastName,
     BirthDate = DateTime.Now.AddYears(-30),
     Job = person.Job,
     ActivityId = Int32.Parse(person.ActivityId),
     SummaryId = Int32.Parse(person.SummaryId),
     EducationLevelId = Int32.Parse(person.EducationLevel),
     Salary = Decimal.Parse(person.Salary),
     JobLevelId = Int32.Parse(person.JobLevel)
       };
     _personsRepository.Set(p);
     return this.RedirectToAction(
       "List", new { summaryId = p.SummaryId.ToString(), activityId = p.ActivityId.ToString() });
       }
       return this.View(person);
 }