Esempio n. 1
0
        public ActionResult Create([Bind(Include = "ContactId,ContactNumber,Type,PersonId")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.Add(contact);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PersonId = new SelectList(db.People, "PersonId", "FirstName", contact.PersonId);
            return(View(contact));
        }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "PersonId,FirstName,MiddleName,LastName,DateOfBirth,AddedOn,AddedBy,HomeAddress,HomeCity,FaceBookAccountId,LinkedInId,UpdateOn,ImagePath,TwitterId,EmailId")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.People.Add(person);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AddedBy = new SelectList(db.AspNetUsers, "Id", "Email", person.AddedBy);
            return(View(person));
        }
Esempio n. 3
0
        public ViewResult PersonDetails()
        {
            // Person dbObj = new Person();
            // dbObj.PersonId = ICollection. ;
            PhoneBookDbEntities1 db       = new PhoneBookDbEntities1();
            List <Person>        list     = db.People.ToList();
            List <Person>        viewlist = new List <Person>();
            Person obj = new Person();
            Person

            s.PersonId = s.PersonId;

            obj.FirstName         = s.FirstName;
            obj.MiddleName        = s.MiddleName;
            obj.LastName          = s.LastName;
            obj.HomeAddress       = s.HomeAddress;
            obj.HomeCity          = s.HomeCity;
            obj.LinkedInId        = s.LinkedInId;
            obj.TwitterId         = s.TwitterId;
            obj.FaceBookAccountId = s.FaceBookAccountId;
            obj.EmailId           = s.EmailId;
            obj.AddedBy           = s.AddedBy;
            obj.AddedOn           = DateTime.Now;



            db.People.Add(obj);
            db.SaveChanges();

            return(View());
        }
Esempio n. 4
0
        public ActionResult Create(Person collection)
        {
            try
            {
                PhoneBookDbEntities1 db = new PhoneBookDbEntities1();
                Person obj = new Person();
                obj.PersonId          = collection.PersonId;
                obj.FirstName         = collection.FirstName;
                obj.MiddleName        = collection.MiddleName;
                obj.LastName          = collection.LastName;
                obj.DateOfBirth       = collection.DateOfBirth;
                obj.AddedOn           = collection.AddedOn;
                obj.AddedBy           = collection.AddedBy;
                obj.HomeAddress       = collection.HomeAddress;
                obj.HomeCity          = collection.HomeCity;
                obj.FaceBookAccountId = collection.FaceBookAccountId;
                obj.UpdateOn          = collection.UpdateOn;
                obj.ImagePath         = collection.ImagePath;
                obj.LinkedInId        = collection.LinkedInId;
                obj.TwitterId         = collection.TwitterId;
                obj.EmailId           = collection.EmailId;
                obj.AddedBy           = User.Identity.GetUserId();
                db.People.Add(obj);
                db.SaveChanges();
                // TODO: Add insert logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Create(PersonViewModel obj)
        {
            try
            {
                Person s = new Person();
                s.DateOfBirth = obj.DateOfBirth;
                s.EmailId = obj.EmailId;
                s.FirstName = obj.FirstName;
                s.MiddleName = obj.MiddleName;
                s.LastName = obj.LastName;
                s.PersonId = obj.PersonId;
                s.AddedBy = obj.AddedBy;
                s.AddedOn = obj.AddedOn;
                s.HomeAddress = obj.HomeAddress;
                s.HomeCity = obj.HomeCity;
                s.FaceBookAccountId = obj.FaceBookAccountId;
                s.TwitterId = obj.TwitterId;
                s.LinkedInId = obj.LinkedInId;
                s.UpdateOn = obj.UpdateOn;
                s.ImagePath = obj.ImagePath;

                PhoneBookDbEntities1 db = new PhoneBookDbEntities1();
                db.People.Add(s);
                db.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
(System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                            validationErrors.Entry.Entity.ToString(),
                            validationError.ErrorMessage);
                        // raise a new exception nesting  
                        // the current instance as InnerException  
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }
            }
Esempio n. 6
0
        public ViewResult add_contacts()
        {
            PhoneBookDbEntities1 db       = new PhoneBookDbEntities1();
            List <Contact>       list     = db.Contacts.ToList();
            List <Contact>       viewlist = new List <Contact>();
            Contact obj = new Contact();

            foreach (Contact s in list)
            {
                obj.ContactNumber = s.ContactNumber;
                obj.ContactId     = s.ContactId;
                obj.Type          = s.Type;
                obj.PersonId      = s.PersonId;
            }
            db.Contacts.Add(obj);
            db.SaveChanges();
            return(View());
        }
        public ActionResult AddContact(Contact collection)
        {
            try
            {
                Contact contact = new Contact();
                contact.ContactNumber = collection.ContactNumber;
                contact.Type          = collection.Type;
                PhoneBookDbEntities1 db = new PhoneBookDbEntities1();
                if (ModelState.IsValid)
                {
                    db.Contacts.Add(contact);
                    db.SaveChanges();



                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult AddPerson(PersonViewModel collection)
        {
            try
            {
                Person person = new Person();
                person.FirstName  = collection.FirstName;
                person.MiddleName = collection.MiddleName;
                person.LastName   = collection.LastName;

                person.AddedOn           = DateTime.Now;
                person.AddedBy           = User.Identity.GetUserId();
                person.HomeAddress       = collection.HomeAddress;
                person.HomeCity          = collection.HomeCity;
                person.EmailId           = collection.EmailId;
                person.FaceBookAccountId = collection.FacebookId;
                person.UpdateOn          = DateTime.Now;
                person.LinkedInId        = collection.LinkedInId;
                person.TwitterId         = collection.TwitterId;

                PhoneBookDbEntities1 db = new PhoneBookDbEntities1();
                if (ModelState.IsValid)
                {
                    db.People.Add(person);
                    db.SaveChanges();



                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Index"));
        }