Пример #1
0
        public ActionResult CreateEdit(PhoneCreateEditVM model)
        {
            Contact contact = GetUserContact(model.ContactID);

            if (contact == null)
            {
                return(HttpNotFound());
            }

            model.Contact = contact;

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

            Phone phone;

            PhoneRepository phoneRepo = new PhoneRepository();

            if (model.ID > 0) // Edit
            {
                phone = phoneRepo.GetById(model.ID);

                if (phone == null || phone.ContactID != model.ContactID)
                {
                    return(HttpNotFound());
                }
            }

            else // Create
            {
                phone = new Phone()
                {
                    ContactID = model.ContactID
                };
            }

            phone.PhoneNumber = model.PhoneNumber;

            phoneRepo.Save(phone);

            return(RedirectToAction("Index", new { id = phone.ContactID }));
        }
Пример #2
0
        public ActionResult Details(int?id)  //phoneID
        {
            if (id != null)
            {
                PhoneRepository phoneRepo = new PhoneRepository();

                Phone phone = phoneRepo.GetById(id.Value);

                if (phone != null && CheckIfContactsUserIsLogged(phone))
                {
                    PhoneCreateEditVM p = new PhoneCreateEditVM()
                    {
                        ID          = phone.ID,
                        Contact     = phone.Contact,
                        PhoneNumber = phone.PhoneNumber
                    };

                    return(View(p));
                }
            }

            return(HttpNotFound());
        }
Пример #3
0
        public ActionResult CreateEdit(int?id, int?contactId)
        {
            if (id == null && contactId != null) // Create
            {
                Contact contact = GetUserContact(contactId.Value);

                if (contact != null)
                {
                    return(View(new PhoneCreateEditVM()
                    {
                        Contact = contact
                    }));
                }
            }

            if (id > 0) // Edit
            {
                PhoneRepository phoneRepo = new PhoneRepository();

                Phone phone = phoneRepo.GetById(id.Value);

                if (phone != null && CheckIfContactsUserIsLogged(phone))
                {
                    PhoneCreateEditVM p = new PhoneCreateEditVM()
                    {
                        ID          = phone.ID,
                        Contact     = phone.Contact,
                        ContactID   = phone.ContactID,
                        PhoneNumber = phone.PhoneNumber
                    };

                    return(View(p));
                }
            }

            return(HttpNotFound());
        }