public ActionResult Create(PersonViewModel Modelperson) { try { // TODO: Add insert logic here //PhoneBookDbEntities db = new PhoneBookDbEntities(); Person person = new Person(); person.FirstName = Modelperson.FirstName; person.MiddleName = Modelperson.MiddleName; person.LastName = Modelperson.LastName; person.AddedOn = DateTime.Now; person.AddedBy = User.Identity.GetUserId(); person.UpdateOn = DateTime.Now; person.DateOfBirth = Modelperson.DateOfBirth; person.HomeAddress = Modelperson.HomeAddress; person.HomeCity = Modelperson.HomeCity; person.FaceBookAccountId = Modelperson.FaceBookAccountId; person.LinkedInId = Modelperson.LinkedInId; person.TwitterId = Modelperson.TwitterId; person.EmailId = Modelperson.EmailId; person.ImagePath = Modelperson.ImagePath; db.People.Add(person); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { String error = ex.Message; return(View()); } }
public ActionResult Create(Person obj) { // TODO: Add insert logic here // to get user identity String user = User.Identity.GetUserId(); Person p = new Person(); //set this new person from the data entered in the form p.FirstName = obj.FirstName; p.MiddleName = obj.MiddleName; p.LastName = obj.LastName; p.DateOfBirth = obj.DateOfBirth; p.AddedOn = DateTime.Now; p.AddedBy = user; p.HomeAddress = obj.HomeAddress; p.HomeCity = obj.HomeCity; p.FaceBookAccountId = obj.FaceBookAccountId; p.LinkedInId = obj.LinkedInId; p.TwitterId = obj.TwitterId; p.EmailId = obj.EmailId; // add it into the database db.People.Add(p); //save update database db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here PhoneBookDbEntities db = new PhoneBookDbEntities(); var contacts = db.Contacts.Where(x => x.PersonId == id); foreach (var i in contacts) { Contact c = new Contact() { ContactId = i.ContactId }; db.Entry(c).State = System.Data.Entity.EntityState.Deleted; } db.SaveChanges(); //var person = db.Person.Where(x => x.PersonId == id).First(); Person p = new Person() { PersonId = id }; db.Entry(p).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Delete(int id, PersonViewModel collection) { try { PhoneBookDbEntities db = new PhoneBookDbEntities(); var contacts = db.Contacts.Where(x => x.PersonId == id); //Condition to check the Id of specific person to edit only his/her details foreach (var i in contacts) { Contact c = new Contact() { ContactId = i.ContactId }; db.Entry(c).State = System.Data.Entity.EntityState.Deleted; } db.SaveChanges(); //var person = db.Person.Where(x => x.PersonId == id).First(); Person p = new Person() { PersonId = id }; db.Entry(p).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); //return Content("delete"); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(Person getPerson) { try { string login = User.Identity.GetUserId(); // TODO: Add insert logic here Person StorePerson = new Person(); StorePerson.FirstName = getPerson.FirstName; StorePerson.MiddleName = getPerson.MiddleName; StorePerson.LastName = getPerson.LastName; StorePerson.DateOfBirth = getPerson.DateOfBirth; StorePerson.FaceBookAccountId = getPerson.FaceBookAccountId; StorePerson.TwitterId = getPerson.TwitterId; StorePerson.LinkedInId = getPerson.LinkedInId; StorePerson.HomeAddress = getPerson.HomeAddress; StorePerson.AddedOn = DateTime.Now; StorePerson.UpdateOn = DateTime.Now; StorePerson.AddedBy = login; StorePerson.EmailId = getPerson.EmailId; StorePerson.HomeCity = getPerson.HomeCity; _db.People.Add(StorePerson); _db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
// GET: PersonViewModel/Delete/5 public ActionResult Delete(int id) { PhoneBookDbEntities db = new PhoneBookDbEntities(); var contacts = db.Contacts.Where(x => x.PersonId == id); foreach (var i in contacts) { Contact c = new Contact() { ContactId = i.ContactId }; db.Entry(c).State = System.Data.Entity.EntityState.Deleted; } db.SaveChanges(); //var person = db.Person.Where(x => x.PersonId == id).First(); Person p = new Person() { PersonId = id }; db.Entry(p).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); return(View()); }
public ActionResult Create(Person collection) { string user = User.Identity.GetUserId(); try { Person p = new Person(); p.FirstName = collection.FirstName; p.MiddleName = collection.MiddleName; p.LastName = collection.LastName; p.AddedOn = DateTime.Now; p.DateOfBirth = collection.DateOfBirth; p.FaceBookAccountId = collection.FaceBookAccountId; p.TwitterId = collection.TwitterId; p.LinkedInId = collection.LinkedInId; p.EmailId = collection.EmailId; p.HomeCity = collection.HomeCity; p.HomeAddress = collection.HomeAddress; p.AddedBy = user; db.People.Add(p); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create([Bind(Include = "Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,AccessFailedCount,UserName")] AspNetUser aspNetUser) { if (ModelState.IsValid) { db.AspNetUsers.Add(aspNetUser); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(aspNetUser)); }
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)); }
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)); }
public ActionResult Create([Bind(Include = "ContactId,ContactNumber,Type,PersonId")] Contact contact) { if (ModelState.IsValid) { int id = contact.PersonId; db.Contacts.Add(contact); db.SaveChanges(); return(Redirect(string.Format("~/Contacts/pc/{0}", id))); } ViewBag.PersonId = new SelectList(db.Person, "PersonId", "FirstName", contact.PersonId); return(View(contact)); }
public ActionResult Edit(int id, PersonViewModel collection) { try { // TODO: Add update logic here PhoneBookDbEntities db = new PhoneBookDbEntities(); var i = db.Person.Where(y => y.PersonId == id).First(); i.FirstName = collection.FirstName; i.LastName = collection.LastName; i.MiddleName = collection.MiddleName; i.DateOfBirth = collection.DateOfBirth; //i.AddedBy = i.AddedBy; //i.AddedOn = Convert.ToDateTime(i.AddedOn); i.HomeAddress = i.HomeAddress; i.HomeCity = i.HomeCity; i.FaceBookAccountId = i.FaceBookAccountId; i.LinkedInId = i.LinkedInId; i.UpdateOn = DateTime.Now; i.ImagePath = i.ImagePath; i.TwitterId = i.TwitterId; i.EmailId = i.EmailId; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(ASPNetUsers collection) { try { // Do not initialize this variable here. AspNetUser obj = new AspNetUser(); obj.Id = collection.Id; obj.Email = collection.Email; obj.EmailConfirmed = collection.EmailConfirmed; obj.PasswordHash = collection.PasswordHash; obj.PhoneNumberConfirmed = collection.PhoneNumberConfirmed; obj.TwoFactorEnabled = collection.TwoFactorEnabled; obj.LockoutEndDateUtc = collection.LockoutEndDateUtc; obj.LockoutEnabled = collection.LockoutEnabled; obj.AccessFailedCount = collection.AccessFailedCount; obj.UserName = collection.UserName; PhoneBookDbEntities db = new PhoneBookDbEntities(); db.AspNetUsers.Add(obj); db.SaveChanges(); } catch (Exception ex) { return(View("Not done", new HandleErrorInfo(ex, "collection", "Create"))); } return(RedirectToAction("Index")); }
public ActionResult Create(personviewmodel collection) { PhoneBookDbEntities db = new PhoneBookDbEntities(); try { // TODO: Add insert logic here Person p1 = new Person(); p1.AddedBy = User.Identity.GetUserId(); p1.AddedOn = DateTime.Now.Date; p1.DateOfBirth = collection.DateOfBirth; p1.EmailId = collection.EmailId; p1.FaceBookAccountId = collection.FaceBookAccountId; p1.FirstName = collection.FirstName; p1.HomeAddress = collection.HomeAddress; p1.HomeCity = collection.HomeCity; p1.ImagePath = collection.ImagePath; p1.LastName = collection.LastName; p1.LinkedInId = collection.LinkedInId; p1.MiddleName = collection.MiddleName; p1.PersonId = collection.PersonId; p1.TwitterId = collection.TwitterId; p1.UpdateOn = DateTime.Now.Date; db.People.Add(p1); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
// GET: PersonDashBoard/Delete/5 public ActionResult Delete(int id) { PhoneBookDbEntities db = new PhoneBookDbEntities(); foreach (Contact c in db.Contacts) { if (c.PersonId == id) { db.Contacts.Remove(c); } } Person myperson = new Person(); foreach (Person p in db.People) { if (p.PersonId == id) { myperson = p; break; } } db.People.Remove(myperson); db.SaveChanges(); return(RedirectToAction("Create", "PersonDashBoard")); }
public ActionResult Create(PersonModel collection) { try { // TODO: Add insert logic here PhoneBookDbEntities db = new PhoneBookDbEntities(); Person p = new Person(); p.FirstName = collection.FirstName; p.MiddleName = collection.MiddleName; p.LastName = collection.LastName; p.DateOfBirth = collection.DateOfBirth; p.AddedBy = User.Identity.GetUserId(); p.AddedOn = collection.AddedOn; p.HomeAddress = collection.HomeAddress; p.HomeCity = collection.HomeCity; p.FaceBookAccountId = collection.FaceBookAccountId; p.LinkedInId = collection.LlinkedInId; p.UpdateOn = Convert.ToDateTime(collection.UpdateOn); p.ImagePath = collection.ImagePath; p.TwitterId = collection.TwitterId; p.EmailId = collection.EmailId; db.Person.Add(p); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, Person collection) { try { // TODO: Add update logic here PhoneBookDbEntities db = new PhoneBookDbEntities(); Person obj = db.People.Find(id); obj.FirstName = collection.FirstName; obj.MiddleName = collection.MiddleName; obj.LastName = collection.LastName; obj.DateOfBirth = collection.DateOfBirth; obj.EmailId = collection.EmailId; obj.FaceBookAccountId = collection.FaceBookAccountId; obj.HomeAddress = collection.HomeAddress; obj.LinkedInId = collection.LinkedInId; obj.ImagePath = collection.ImagePath; obj.TwitterId = collection.TwitterId; obj.UpdateOn = DateTime.Now; obj.HomeCity = collection.HomeCity; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(CreatPersonViewModel obj) { Person p = new Person(); p.FirstName = obj.FirstName; p.MiddleName = obj.MiddleName; p.LastName = obj.LastName; p.LinkedInId = obj.LinkedInId; p.HomeAddress = obj.HomeAddress; p.HomeCity = obj.HomeCity; p.EmailId = obj.EmailId; p.TwitterId = obj.TwitterId; p.DateOfBirth = obj.DateOfBirth; p.FaceBookAccountId = obj.FaceBookAccountId; p.ImagePath = obj.ImagePath; p.AddedOn = DateTime.Now; p.UpdateOn = DateTime.Now; PhoneBookDbEntities db = new PhoneBookDbEntities(); string id = User.Identity.GetUserId(); p.AddedBy = id; db.People.Add(p); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(int id, personviewmodel collection) { PhoneBookDbEntities db = new PhoneBookDbEntities(); var p1 = db.People.Where(x => x.PersonId == id).First(); try { // TODO: Add update logic here p1.AddedBy = Convert.ToString(User.Identity.GetUserId()); p1.AddedOn = DateTime.Now.Date; p1.DateOfBirth = collection.DateOfBirth; p1.EmailId = collection.EmailId; p1.FaceBookAccountId = collection.FaceBookAccountId; p1.FirstName = collection.FirstName; p1.HomeAddress = collection.HomeAddress; p1.HomeCity = collection.HomeCity; p1.ImagePath = collection.ImagePath; p1.LastName = collection.LastName; p1.LinkedInId = collection.LinkedInId; p1.MiddleName = collection.MiddleName; p1.PersonId = collection.PersonId; p1.TwitterId = collection.TwitterId; p1.UpdateOn = DateTime.Now.Date; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View(p1)); } }
public ActionResult Create(Person p) { string admin = User.Identity.GetUserId(); try { // TODO: Add insert logic here Person obj = new Person(); obj.FirstName = p.FirstName; obj.MiddleName = p.MiddleName; obj.LastName = p.LastName; obj.LinkedInId = p.LinkedInId; obj.FaceBookAccountId = p.FaceBookAccountId; obj.EmailId = p.EmailId; obj.AddedOn = DateTime.Now; obj.AddedBy = admin; obj.DateOfBirth = p.DateOfBirth; obj.TwitterId = p.TwitterId; obj.HomeAddress = p.HomeAddress; obj.HomeCity = p.HomeCity; db.People.Add(obj); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult DeleteConfirmed(int id) { try { PhoneBookDbEntities db = new PhoneBookDbEntities(); Person p = db.People.Find(id); PersonViewModel a = new PersonViewModel(); a.PersonId = p.PersonId; a.FirstName = p.FirstName; a.MiddleName = p.MiddleName; a.LastName = p.LastName; a.DateOfBirth = p.DateOfBirth; a.AddedOn = p.AddedOn; a.AddedBy = p.AddedBy; a.HomeAddress = p.HomeAddress; a.HomeCity = p.HomeCity; a.FaceBookAccountId = p.FaceBookAccountId; a.TwitterId = p.TwitterId; a.UpdateOn = p.UpdateOn; a.ImagePath = p.ImagePath; a.LinkedInId = p.LinkedInId; a.EmailId = p.EmailId; db.People.Remove(p); db.SaveChanges(); return(RedirectToAction("Index", new { id = User.Identity.GetUserId() })); } catch { return(View()); } }
public ActionResult Create(PersonViewModel collection) { try { // TODO: Add insert logic here PhoneBookDbEntities db = new PhoneBookDbEntities(); Person ac = new Person(); ac.PersonId = collection.PersonId; ac.FirstName = collection.FirstName; ac.MiddleName = collection.MiddleName; ac.LastName = collection.LastName; ac.DateOfBirth = collection.DateOfBirth; ac.HomeAddress = collection.HomeAddress; ac.HomeCity = collection.HomeCity; ac.FaceBookAccountId = collection.FaceBookAccountId; ac.TwitterId = collection.TwitterId; ac.EmailId = collection.EmailId; ac.AddedBy = User.Identity.GetUserId(); ac.AddedOn = DateTime.Now; ac.UpdateOn = DateTime.Now; db.People.Add(ac); db.SaveChanges(); } catch (Exception ex) { return(View()); } return(RedirectToAction("Index")); }
public ActionResult Create(Person c) { try { Person s = new Person(); s.FirstName = c.FirstName; s.MiddleName = c.MiddleName; s.LastName = c.LastName; s.DateOfBirth = c.DateOfBirth; s.AddedOn = c.AddedOn; s.AddedBy = c.AddedBy; s.HomeAddress = c.HomeAddress; s.HomeCity = c.HomeCity; s.FaceBookAccountId = c.FaceBookAccountId; s.LinkedIn = c.LinkedIn; s.UpdatedOn = c.UpdatedOn; s.ImagePath = c.ImagePath; s.TwitterId = c.TwitterId; s.EamilId = c.EamilId; PhoneBookDbEntities db = new PhoneBookDbEntities(); db.People.Add(s); db.SaveChanges(); // TODO: Add insert logic here // Person obj = new Person(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(PersonViewModel obj) { try { Person p = new Person(); p.FirstName = obj.FirstName; p.MiddleName = obj.MiddleName; p.LastName = obj.LastName; p.DateOfBirth = obj.DateOfBirth; p.AddedOn = obj.AddedOn; p.AddedBy = obj.AddedBy; p.HomeAddress = obj.HomeAddress; p.HomeCity = obj.HomeCity; p.FaceBookAccountId = obj.FaceBookAccountId; p.LinkedInId = obj.LinkedInId; p.UpdateOn = obj.UpdateOn; p.ImagePath = obj.ImagePath; p.TwitterId = obj.TwitterId; p.EmailId = obj.EmailId; using (PhoneBookDbEntities db = new PhoneBookDbEntities()) { db.People.Add(p); db.SaveChanges(); } // TODO: Add insert logic here return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(PersonViewModel collection) { try { // TODO: Add insert logic here string id = User.Identity.GetUserId().ToString(); PhoneBookDbEntities db = new PhoneBookDbEntities(); Person obj = new Person(); obj.FirstName = collection.FirstName; obj.MiddleName = collection.MiddleName; obj.LastName = collection.LastName; obj.AddedBy = id; obj.AddedOn = DateTime.Now; obj.DateOfBirth = collection.DateOfBirth; obj.EmailId = collection.EmailId; obj.FaceBookAccountId = collection.FaceBookAccountId; obj.HomeAddress = collection.HomeAddress; obj.LinkedInId = collection.LinkedInId; obj.ImagePath = collection.ImagePath; obj.TwitterId = collection.TwitterId; obj.UpdateOn = collection.UpdateOn; obj.HomeCity = collection.HomeCity; db.People.Add(obj); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, PersonViewModel collection) { try { PhoneBookDbEntities db = new PhoneBookDbEntities(); var p = db.Person.Where(x => x.PersonId == id).First(); //Condition to check the Id of specific person to edit only his/her details p.FirstName = collection.FirstName; p.MiddleName = collection.MiddleName; p.LastName = collection.LastName; p.DateOfBirth = Convert.ToDateTime(collection.DateOfBirth); p.AddedOn = collection.AddedOn; p.HomeAddress = collection.HomeAddress; p.HomeCity = collection.HomeCity; p.FaceBookAccountId = collection.FaceBookAccountId; p.LinkedInId = collection.LinkedInId; p.UpdateOn = Convert.ToDateTime(collection.UpdateOn); p.ImagePath = collection.ImagePath; p.TwitterId = collection.TwitterId; p.EmailId = collection.EmailId; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Delete(int id, personviewmodel collection) { PhoneBookDbEntities db = new PhoneBookDbEntities(); Person delable = new Person(); var converter = db.People; try { foreach (var member in converter) { if (member.PersonId == id) { delable = member; } } db.People.Remove(delable); db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View(delable)); } }
public ActionResult Edit(int id, PersonViewModel p) { PhoneBookDbEntities db = new PhoneBookDbEntities(); if (ModelState.IsValid) { Person a = db.People.Find(id); a.PersonId = p.PersonId; a.FirstName = p.FirstName; a.MiddleName = p.MiddleName; a.LastName = p.LastName; a.DateOfBirth = p.DateOfBirth; a.AddedOn = p.AddedOn; a.AddedBy = p.AddedBy; a.HomeAddress = p.HomeAddress; a.HomeCity = p.HomeCity; a.FaceBookAccountId = p.FaceBookAccountId; a.TwitterId = p.TwitterId; a.UpdateOn = DateTime.Now.Date; a.ImagePath = p.ImagePath; a.LinkedInId = p.LinkedInId; a.EmailId = p.EmailId; db.Entry(a).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index", new { id = User.Identity.GetUserId() })); } ViewBag.AddedBy = new SelectList(db.AspNetUsers, "Id", "Email", p.AddedBy); return(View(p)); //catch //{ // return View(); //} }
public ActionResult Edit(int id, EditPersonViewModel obj) { try { PhoneBookDbEntities db = new PhoneBookDbEntities(); db.People.Find(id).FirstName = obj.FirstName; db.People.Find(id).LastName = obj.LastName; db.People.Find(id).MiddleName = obj.MiddleName; db.People.Find(id).HomeAddress = obj.HomeAddress; db.People.Find(id).HomeCity = obj.HomeCity; db.People.Find(id).ImagePath = obj.ImagePath; db.People.Find(id).TwitterId = obj.TwitterId; db.People.Find(id).FaceBookAccountId = obj.FaceBookAccountId; db.People.Find(id).EmailId = obj.EmailId; db.People.Find(id).DateOfBirth = obj.DateOfBirth; db.People.Find(id).LinkedInId = obj.LinkedInId; db.SaveChanges(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(ContactViewModel obj) { try { Contact c = new Contact(); c.ContactId = obj.ContactId; c.ContactNumber = obj.ContactNumber; c.Type = obj.Type; c.PersonId = obj.PersonId; using (PhoneBookDbEntities db = new PhoneBookDbEntities()) { db.Contacts.Add(c); db.SaveChanges(); } // TODO: Add insert logic here return(RedirectToAction("Index")); } catch { return(View()); } }