public ActionResult Edit(string id, string name, string address, string classId, string birthDate, string gender) { var student = new Students { Id = Convert.ToInt32(id), Name = name, Address = address, ClassId = Convert.ToInt32(classId), Birthdate = Convert.ToDateTime(birthDate), Gender = gender }; DataRepository.StudentsProvider.Update(student); return RedirectToAction("Index"); }
public ActionResult Create(string name,string address,string classId,string birthDate,string gender) { if(ModelState.IsValid) { var student = new Students { Name = name, Address = address, ClassId = Convert.ToInt32(classId), Birthdate = Convert.ToDateTime(birthDate), Gender = gender }; DataRepository.StudentsProvider.Insert(student); return RedirectToAction("Index"); } return View(new Students()); }
/// <summary> /// Update an existing row in the datasource. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">School.Entities.Students object to update.</param> /// <remarks> /// After updating the datasource, the School.Entities.Students object will be updated /// to refelect any changes made by the datasource. (ie: identity or computed columns) /// </remarks> /// <returns>Returns true if operation is successful.</returns> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override bool Update(TransactionManager transactionManager, School.Entities.Students entity) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Students_Update", _useStoredProcedure); database.AddInParameter(commandWrapper, "@Id", DbType.Int32, entity.Id); database.AddInParameter(commandWrapper, "@Name", DbType.String, entity.Name); database.AddInParameter(commandWrapper, "@Address", DbType.String, entity.Address); database.AddInParameter(commandWrapper, "@ClassId", DbType.Int32, entity.ClassId); database.AddInParameter(commandWrapper, "@Birthdate", DbType.Date, entity.Birthdate); database.AddInParameter(commandWrapper, "@Gender", DbType.String, entity.Gender); int results = 0; //Provider Data Requesting Command Event OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity)); if (transactionManager != null) { results = Utility.ExecuteNonQuery(transactionManager, commandWrapper); } else { results = Utility.ExecuteNonQuery(database, commandWrapper); } //Stop Tracking Now that it has been updated and persisted. if (DataRepository.Provider.EnableEntityTracking) { EntityManager.StopTracking(entity.EntityTrackingKey); } entity.AcceptChanges(); //Provider Data Requested Command Event OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity)); return(Convert.ToBoolean(results)); }
/// <summary> /// Inserts a School.Entities.Students object into the datasource using a transaction. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">School.Entities.Students object to insert.</param> /// <remarks> /// After inserting into the datasource, the School.Entities.Students object will be updated /// to refelect any changes made by the datasource. (ie: identity or computed columns) /// </remarks> /// <returns>Returns true if operation is successful.</returns> /// <exception cref="System.Exception">The command could not be executed.</exception> /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception> /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception> public override bool Insert(TransactionManager transactionManager, School.Entities.Students entity) { SqlDatabase database = new SqlDatabase(this._connectionString); DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Students_Insert", _useStoredProcedure); database.AddOutParameter(commandWrapper, "@Id", DbType.Int32, 4); database.AddInParameter(commandWrapper, "@Name", DbType.String, entity.Name); database.AddInParameter(commandWrapper, "@Address", DbType.String, entity.Address); database.AddInParameter(commandWrapper, "@ClassId", DbType.Int32, entity.ClassId); database.AddInParameter(commandWrapper, "@Birthdate", DbType.Date, entity.Birthdate); database.AddInParameter(commandWrapper, "@Gender", DbType.String, entity.Gender); int results = 0; //Provider Data Requesting Command Event OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity)); if (transactionManager != null) { results = Utility.ExecuteNonQuery(transactionManager, commandWrapper); } else { results = Utility.ExecuteNonQuery(database, commandWrapper); } object _id = database.GetParameterValue(commandWrapper, "@Id"); entity.Id = (System.Int32)_id; entity.AcceptChanges(); //Provider Data Requested Command Event OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity)); return(Convert.ToBoolean(results)); }
public ActionResult Edit(Students student) { DataRepository.StudentsProvider.Update(student); return RedirectToAction("Index"); }