コード例 #1
0
ファイル: HomeController.cs プロジェクト: zhaoyangsoft/HTML5
        public JsonResult Create(Person[] contact)
        {
            try
            {
                int maxId = 0;
                IQueryable<Person> max = db.People.OrderByDescending(t => t.BusinessEntityID).Take(1);
                foreach (Person p in max)
                {
                    maxId = p.BusinessEntityID;
                }
                foreach (Person ps in contact)
                {
                    ps.BusinessEntityID = ++maxId;
                    db.People.AddObject(ps);
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                return Json(new
                {
                    data = "",
                    success = false,
                    message = ex.Message
                });
            }

            return Json(new
            {
                data = contact,
                success = true,
                message = "Create method called successfully"
            });
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: zhaoyangsoft/HTML5
        public JsonResult Delete(Person contact)
        {
            Person t = db.People.Single(c => c.BusinessEntityID == contact.BusinessEntityID);
            db.People.DeleteObject(t);
            db.SaveChanges();

            return Json(new
            {
                data = contact,
                success = true,
                message = "Delete method called successfully"
            });
        }
コード例 #3
0
ファイル: Model1.Designer.cs プロジェクト: zhaoyangsoft/HTML5
 /// <summary>
 /// Deprecated Method for adding a new object to the People EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPeople(Person person)
 {
     base.AddObject("People", person);
 }
コード例 #4
0
ファイル: HomeController.cs プロジェクト: zhaoyangsoft/HTML5
        public JsonResult UpdateAll(Person[] contact)
        {
            try
            {
                //// Get around DateTime issue. We just ignore the ModifiedDate changes.
                //Contact t = db.Contacts.Single(c => c.ContactID == contact.ContactID);
                //contact.ModifiedDate = t.ModifiedDate;
                //db.Contacts.Detach(t);
                //// -----------------------------------------------------------------------------------

                foreach (Person ps in contact)
                {
                    db.People.Attach(ps);
                    db.ObjectStateManager.ChangeObjectState(ps, System.Data.EntityState.Modified);
                }
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return Json(new
            {
                data = contact,
                success = true,
                message = "Update method called successfully"
            });
        }
コード例 #5
0
ファイル: Model1.Designer.cs プロジェクト: zhaoyangsoft/HTML5
 /// <summary>
 /// Create a new Person object.
 /// </summary>
 /// <param name="businessEntityID">Initial value of the BusinessEntityID property.</param>
 /// <param name="personType">Initial value of the PersonType property.</param>
 /// <param name="firstName">Initial value of the FirstName property.</param>
 /// <param name="lastName">Initial value of the LastName property.</param>
 /// <param name="modifiedDate">Initial value of the ModifiedDate property.</param>
 /// <param name="gender">Initial value of the Gender property.</param>
 /// <param name="age">Initial value of the Age property.</param>
 /// <param name="major">Initial value of the Major property.</param>
 /// <param name="phone">Initial value of the Phone property.</param>
 /// <param name="email">Initial value of the Email property.</param>
 /// <param name="location">Initial value of the Location property.</param>
 public static Person CreatePerson(global::System.Int32 businessEntityID, global::System.String personType, global::System.String firstName, global::System.String lastName, global::System.DateTime modifiedDate, global::System.String gender, global::System.Int32 age, global::System.String major, global::System.String phone, global::System.String email, global::System.String location)
 {
     Person person = new Person();
     person.BusinessEntityID = businessEntityID;
     person.PersonType = personType;
     person.FirstName = firstName;
     person.LastName = lastName;
     person.ModifiedDate = modifiedDate;
     person.Gender = gender;
     person.Age = age;
     person.Major = major;
     person.Phone = phone;
     person.Email = email;
     person.Location = location;
     return person;
 }