Exemplo n.º 1
0
        public ActionResult Edit()
        {
            UnitOfWork    unit         = new UnitOfWork();
            PhonesService phoneService = new PhonesService(unit);
            PhoneEditVM   model        = new PhoneEditVM();

            TryUpdateModel(model);
            Phone p;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.ID != 0)
            {
                p = phoneService.GetByID(model.ID);
            }
            else
            {
                p = new Phone();
            }


            Mapper.Map(model, p);

            phoneService.Save(p);
            return(this.RedirectToAction(c => c.List(), new { contactID = model.ContactID }));
        }
Exemplo n.º 2
0
        private void BtnCreatePhone_Click(object sender, EventArgs e)
        {
            Spinner  phoneType   = FindViewById <Spinner>(Resource.Id.spinnerPhoneType);
            EditText phoneNumber = FindViewById <EditText>(Resource.Id.editTextPhoneNumber);

            p.Type      = phoneType.SelectedItem.ToString();
            p.Number    = phoneNumber.Text;
            p.ContactID = MainActivity.SelectedContact.ID;

            PhonesService phonesService = new PhonesService();

            phonesService.Save(p);
            MainActivity.SelectedContact.Phones.Clear();
            MainActivity.SelectedContact.Phones = phonesService.GetPhonesByContactID(MainActivity.SelectedContact.ID).ToList();

            Intent intentResult = new Intent(this, typeof(ViewContactActivity));

            SetResult(Result.Ok, intentResult);
            Finish();
        }
Exemplo n.º 3
0
        public ActionResult Edit()
        {
            PhonesService phonesService = new PhonesService();
            PhonesEditVM  model         = new PhonesEditVM();

            TryUpdateModel(model);

            if (phonesService.GetContact(model.ContactID) == null)
            {
                return(this.RedirectToAction <ContactsController>(c => c.List()));
            }

            Phone phone;

            if (model.ID == 0)
            {
                phone = new Phone();
            }
            else
            {
                phone = phonesService.GetByID(model.ID);
                if (phone == null)
                {
                    return(this.RedirectToAction(c => c.List(), new { ContactID = model.ContactID }));
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Mapper.Map(model, phone);

            phonesService.Save(phone);

            return(this.RedirectToAction(c => c.List(), new { ContactID = model.ContactID }));
        }