Ejemplo n.º 1
0
 public ActionResult AddPerson()
 {
     PersonViewModel person= new PersonViewModel();
     person.UserID = User.Identity.GetUserId();
     List<CountryViewModel> countries = service.GetCountries();
     List<CityViewModel> cities = new List<CityViewModel>();
     List<StreetViewModel> streets = new List<StreetViewModel>();
     var tupleModel = new Tuple<PersonViewModel, List<CountryViewModel>, List<CityViewModel>, List<StreetViewModel>>(person, countries, cities, streets);
     return PartialView(person);
 }
Ejemplo n.º 2
0
 public ActionResult AddPerson()
 {
     PersonViewModel person = new PersonViewModel();
     List<SelectListItem> li = new List<SelectListItem>();
     li.Add(new SelectListItem { Text = "Mobile", Value = "Mobile", Selected=true });
     li.Add(new SelectListItem { Text = "Work", Value = "Work" });
     li.Add(new SelectListItem { Text = "Home", Value = "Home" });
     ViewData["numberTypes"] = li;
     return PartialView();
 }
Ejemplo n.º 3
0
 public void Add(PersonViewModel person)
 {
     try
     {
         Person personR = FromViewModel(person);
         repository.Create(personR);
     }
     catch
     {
         throw new ArgumentException();
     }
 }
Ejemplo n.º 4
0
 public void Delete(PersonViewModel person)
 {
     try
     {
         Person personR = repository.GetByID(person.Id);
         repository.Delete(personR);
     }
     catch
     {
         throw new ArgumentException();
     }
 }
Ejemplo n.º 5
0
 public ActionResult AddPerson()
 {
     PersonViewModel person= new PersonViewModel();
     person.UserID = User.Identity.GetUserId();
     List<CountryViewModel> countries = service.GetCountries();
     ViewBag.CountryID = new SelectList(countries, "CountryID", "CountryName");
     List<CityViewModel> cities = new List<CityViewModel>();
     ViewBag.CitiesID = new SelectList(cities, "CitiesID", "CitiesName");
     List<StreetViewModel> streets = new List<StreetViewModel>();
     ViewBag.StreetID = new SelectList(streets, "StreetsID", "StreetsName");
     //var tupleModel = new Tuple<PersonViewModel, List<CountryViewModel>, List<CityViewModel>, List<StreetViewModel>>(person, countries, cities, streets);
     return PartialView(person);
 }
Ejemplo n.º 6
0
 public ActionResult AddPerson(PersonViewModel person, FormCollection collection)
 {
     person.PhoneNumbers = new List<PhoneNumberViewModel>();
     for (int i=4; i<collection.Count-1; i=i+2)
     {
         if (collection[i]!="" && collection[i+1]!="")
         {
             PhoneNumberViewModel phone = new PhoneNumberViewModel()
             {
                 PhoneNumber = collection[i],
                 PhoneNumberType = collection[i + 1]
             };
             person.PhoneNumbers.Add(phone);
         }
     }
     service.Add(person);
     return RedirectToAction("Index");
 }
Ejemplo n.º 7
0
 public ActionResult AddPerson(PersonViewModel person/*, FormCollection collection*/)
 {
     UserViewModel user = service.GetById(person.UserID);
     user.people.Add(person);
     //person.PhoneNumbers = new List<PhoneNumberViewModel>();
     //for (int i = 4; i < collection.Count - 1; i = i + 2)
     //{
     //    if (collection[i] != "" && collection[i + 1] != "")
     //    {
     //        PhoneNumberViewModel phone = new PhoneNumberViewModel()
     //        {
     //            PhoneNumber = collection[i],
     //            PhoneNumberType = collection[i + 1]
     //        };
     //        person.PhoneNumbers.Add(phone);
     //    }
     //}
     //service.Add(person);
     service.Update(user);
     return RedirectToAction("People");
 }
Ejemplo n.º 8
0
 private PersonViewModel ToViewModel(MongoPerson personR)
 {
     PersonViewModel personVM = new PersonViewModel()
     {
         Id = personR.Id,
         FirstName = personR.FirstName,
         LastName = personR.LastName,
         Age = personR.Age,
         PhoneNumbers = new List<PhoneNumberViewModel>()
     };
     foreach (var pn in personR.phonenumbers)
     {
         personVM.PhoneNumbers.Add(new PhoneNumberViewModel()
         {
             Id = pn.Id,
             PhoneNumber = pn.PhoneNumber,
             PhoneNumberType = pn.PhoneNumberType
         });
     }
     return personVM;
 }
Ejemplo n.º 9
0
 public PersonViewModel ToViewModel(Person personR)
 {
     PersonViewModel personVM = new PersonViewModel()
     {
         Id = personR.ID,
         FirstName = personR.FirstName,
         LastName = personR.LastName,
         Age = personR.Age,
         PhoneNumbers = new List<PhoneNumberViewModel>()
     };
     if (personR.phonenumbers != null)
     {
         foreach (var pn in personR.phonenumbers)
         {
             personVM.PhoneNumbers.Add(new PhoneNumberViewModel()
             {
                 Id = pn.ID,
                 PhoneNumber = pn.PhoneNumber,
                 PhoneNumberType = pn.PhoneNumberType
             });
         }
     }
     return personVM;
 }
Ejemplo n.º 10
0
 public void UpdatePerson(PersonViewModel person)
 {
     Person personR = ToPerson(person);
     repository.UpdatePerson(personR);
 }
Ejemplo n.º 11
0
 public void DeletePerson(PersonViewModel person)
 {
     Person personR = ToPerson(GetPersonById(person.Id));
     repository.DeletePerson(personR);
 }
Ejemplo n.º 12
0
 public ActionResult AddAddress(PersonViewModel pers)
 {
     PersonViewModel per = service.GetPersonById(pers.Id);
     per.Address.Add(pers.Address[pers.Address.Count - 1]);
     service.AddAddress(per);
     return RedirectToAction("People");
 }
Ejemplo n.º 13
0
 public void Add(PersonViewModel person)
 {
     MongoPerson personR = FromViewModel(person);
     repository.Create(personR);
 }
Ejemplo n.º 14
0
 public void Update(PersonViewModel person)
 {
     MongoPerson personR = FromViewModel(person);
     repository.Update(personR);
 }
Ejemplo n.º 15
0
 public ActionResult AddPhoneNumber(PersonViewModel pers)
 {
     PersonViewModel per = service.GetPersonById(pers.Id);
     per.PhoneNumbers.Add(pers.PhoneNumbers[0]);
     service.AddPhoneNumber(per);
     return RedirectToAction("People");
 }
Ejemplo n.º 16
0
 public void Delete(PersonViewModel person)
 {
     MongoPerson personR = repository.GetByID(person.Id);
     repository.Delete(personR);
 }
Ejemplo n.º 17
0
 public ActionResult Delete(PersonViewModel person)
 {
     service.DeletePerson(person);
     return RedirectToAction("People");
 }
Ejemplo n.º 18
0
 public void AddAddress(PersonViewModel person)
 {
     Address address = Mapper.Map<Address>(person.Address[person.Address.Count - 1]);
     address.PersonID = person.Id;
     Person personR = ToPerson(GetPersonById(person.Id));
     personR.addresses.Add(address);
     personR.addresses[personR.addresses.Count - 1].PersonID = person.Id;
     personR.addresses[personR.addresses.Count - 1].person = new List<Person>();
     personR.addresses[personR.addresses.Count - 1].person.Add(personR);
     repositoryPerson.Update(personR);
 }
Ejemplo n.º 19
0
 private Person FromViewModel(PersonViewModel person)
 {
     Person personR = new Person()
     {
         ID = person.Id,
         FirstName = person.FirstName,
         LastName = person.LastName,
         Age = person.Age,
         phonenumbers = new List<PhoneNumbers>()
     };
     foreach (var pn in person.PhoneNumbers)
     {
         if (pn.PhoneNumberType == null)
         {
             throw new ArgumentException();
         }
         personR.phonenumbers.Add(new PhoneNumbers()
         {
             ID = pn.Id,
             PersonID = person.Id,
             PhoneNumber = pn.PhoneNumber,
             PhoneNumberType = pn.PhoneNumberType,
         });
     }
     return personR;
 }
Ejemplo n.º 20
0
 public Person ToPerson(PersonViewModel person)
 {
     Person personR = Mapper.Map<Person>(person);
     personR.addresses = new List<Address>();
     foreach (var add in person.Address)
     {
         Address a = Mapper.Map<Address>(add);
         a.PersonID = person.Id;
         personR.addresses.Add(a);
     }
     personR.phonenumbers = new List<PhoneNumbers>();
     foreach (var ph in person.PhoneNumbers)
     {
         PhoneNumbers p = Mapper.Map<PhoneNumbers>(ph);
         p.PersonID = person.Id;
         personR.phonenumbers.Add(p);
     }
     return personR;
 }
Ejemplo n.º 21
0
 public void SaveOrUpdatePerson(PersonViewModel person, string UserID)
 {
     Person personR = ToPerson(person);
     personR.UserID = UserID;
     repository.SaveOrUpdatePerson(personR);
 }
Ejemplo n.º 22
0
 public ActionResult AddPerson(PersonViewModel person/*, FormCollection collection*/)
 {
     UserViewModel user = service.GetById(User.Identity.GetUserId());
     //person.Address[0].Street.City = service.GetCityByID(Convert.ToInt32(collection[10]));
     //person.Address[0].Street.City.Country = service.GetCountryByID(Convert.ToInt32(collection[11]));
     user.people.Add(person);
     service.Update(user);
     return RedirectToAction("People");
 }
Ejemplo n.º 23
0
 public Person ToPerson(PersonViewModel person)
 {
     Person personR = Mapper.Map<Person>(person);
     personR.addresses = new List<Address>();
     foreach (var add in person.Address)
     {
         personR.addresses.Add(Mapper.Map<Address>(add));
     }
     personR.phonenumbers = new List<PhoneNumbers>();
     foreach (var ph in person.PhoneNumbers)
     {
         personR.phonenumbers.Add(Mapper.Map<PhoneNumbers>(ph));
     }
     return personR;
 }
Ejemplo n.º 24
0
 public ActionResult Edit(PersonViewModel person)
 {
     service.Update(person);
     return RedirectToAction("Index");
 }
Ejemplo n.º 25
0
 public ActionResult Edit(PersonViewModel person)
 {
     service.UpdatePerson(person);
    // service.SaveOrUpdatePerson(person, User.Identity.GetUserId());
     return RedirectToAction("People");
 }
Ejemplo n.º 26
0
 public ActionResult Delete(PersonViewModel person)
 {
     service.Delete(service.GetById(person.Id));
     return RedirectToAction("Index");
 }
Ejemplo n.º 27
0
 public ActionResult AddAddress(PersonViewModel pers)
 {
     PersonViewModel per = service.GetPersonById(pers.Id);
     per.Address.Add(pers.Address[pers.Address.Count - 1]);
     //service.SaveOrUpdatePerson(per, User.Identity.GetUserId());
     service.AddAddress(per);
     return RedirectToAction("People");
 }
Ejemplo n.º 28
0
 public ActionResult Edit(PersonViewModel person)
 {
     service.UpdatePerson(person);
     return RedirectToAction("People");
 }
Ejemplo n.º 29
0
 public ActionResult AddPerson(PersonViewModel person)
 {
     UserViewModel user = service.GetById(User.Identity.GetUserId());
     user.people.Add(person);
     service.Update(user);
     //service.SaveOrUpdatePerson(person, User.Identity.GetUserId());
     return RedirectToAction("People");
 }
Ejemplo n.º 30
0
 public ActionResult AddAddress(PersonViewModel pers, FormCollection collection)
 {
     PersonViewModel per = service.GetPersonById(pers.Id);
     pers.Address[0].lat = collection[8];
     pers.Address[0].lng =collection[9];
     per.Address.Add(pers.Address[0]);
     service.AddAddress(per);
     return RedirectToAction("People");
 }