/// <summary> /// Get SysSample By SysSample ID /// </summary> /// <param name="sysSampleID"></param> /// <returns></returns> public SysSample GetSysSampleById(String sysSampleID) { var sysSampleInformation = dbConnection.SysSamples.First(c => c.Id == sysSampleID); SysSample sysSample = sysSampleInformation as SysSample; return(sysSample); }
/// <summary> /// Create SysSample /// </summary> /// <param name="sysSample"></param> public void CreateSysSample(SysSample sysSample) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = dbConnection; sqlCommand.Transaction = dbTransaction; DateTime dateCreated = System.DateTime.Now; sysSample.CreateTime = dateCreated; StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append(" INSERT INTO SysSample (Id, Name,Age, Bir,Photo, Note, CreateTime)"); sqlBuilder.Append(" VALUES ( @Id, @Name, @Age, @Bir,@Photo, @Note, @CreateTime)"); sqlCommand.CommandText = sqlBuilder.ToString(); sqlCommand.Parameters.Add("@Id", System.Data.SqlDbType.NVarChar); sqlCommand.Parameters.Add("@Name", System.Data.SqlDbType.NVarChar); sqlCommand.Parameters.Add("@Age", System.Data.SqlDbType.NVarChar); sqlCommand.Parameters.Add("@Bir", System.Data.SqlDbType.NVarChar); sqlCommand.Parameters.Add("@Photo", System.Data.SqlDbType.NVarChar); sqlCommand.Parameters.Add("@Note", System.Data.SqlDbType.NVarChar); sqlCommand.Parameters.Add("@CreateTime", System.Data.SqlDbType.DateTime); sqlCommand.Parameters["@Id"].Value = Utilities.GetString(sysSample.Id); sqlCommand.Parameters["@Name"].Value = Utilities.GetString(sysSample.Name); sqlCommand.Parameters["@Age"].Value = Utilities.GetString(sysSample.Age); sqlCommand.Parameters["@Bir"].Value = Utilities.GetString(sysSample.Bir); sqlCommand.Parameters["@Photo"].Value = Utilities.GetString(sysSample.Photo); sqlCommand.Parameters["@Note"].Value = Utilities.GetString(sysSample.Note); sqlCommand.Parameters["@CreateTime"].Value = sysSample.CreateTime; sqlCommand.ExecuteNonQuery(); }
public virtual void Modify(ref ValidationErrors errors, Apps.Models.Sys.SysSampleModel model, params string[] updateProperties) { SysSample entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return; } if (updateProperties.Count() <= 0) { entity.Id = model.Id; entity.Name = model.Name; entity.Age = model.Age; entity.Bir = model.Bir; entity.Photo = model.Photo; entity.Note = model.Note; entity.CreateTime = model.CreateTime; } else { Type type = typeof(Apps.Models.Sys.SysSampleModel); Type typeE = typeof(Apps.Models.SysSample); foreach (var item in updateProperties) { System.Reflection.PropertyInfo pi = type.GetProperty(item); System.Reflection.PropertyInfo piE = typeE.GetProperty(item); piE.SetValue(entity, pi.GetValue(model), null); } } m_Rep.Modify(entity, updateProperties); }
public SysSampleModel GetById(int id) { try { if (IsExist(id)) { SysSample entity = Rep.GetById(id); SysSampleModel model = new SysSampleModel(); model.ID = (int)entity.ID; model.Name = entity.Name; model.Age = entity.Age; model.Bir = entity.Bir; model.Photo = entity.Photo; model.Note = entity.Note; model.CreateTime = entity.CreateTime; return(model); } return(new SysSampleModel()); } catch (Exception ex) { ExceptionHander.WriteException(ex); return(null); } }
/// <summary> /// 修改一个实体 /// </summary> /// <param name="errors">持久的错误信息</param> /// <param name="model">模型</param> /// <returns>是否成功</returns> public bool Edit(ref ValidationErrors errors, SysSampleModel model) { try { SysSample entity = Rep.GetById(model.Id); if (entity == null) { errors.Add(Suggestion.Disable); return(false); } entity.Name = model.Name; entity.Age = model.Age; entity.Bir = model.Bir; entity.Photo = model.Photo; entity.Note = model.Note; if (Rep.Edit(entity) == 1) { return(true); } else { errors.Add(Suggestion.EditFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
/// <summary> /// 保存数据 /// </summary> public virtual void SaveImportData(IEnumerable <SysSampleModel> list) { try { using (DBContainer db = new DBContainer()) { foreach (var model in list) { SysSample entity = new SysSample(); entity.Id = ResultHelper.NewId; entity.Name = model.Name; entity.Age = model.Age; entity.Bir = model.Bir; entity.Photo = model.Photo; entity.Note = model.Note; entity.CreateTime = ResultHelper.NowTime; db.SysSample.Add(entity); } db.SaveChanges(); } } catch (Exception ex) { throw; } }
public bool Create(ref ValidationErrors errors, SysSampleModel model) { try { SysSample entity = Rep.GetById(model.ID); if (entity != null) { errors.Add("主键重复"); return(false); } entity = new SysSample(); entity.ID = model.ID; entity.Name = model.Name; entity.Note = model.Name; entity.Photo = model.Photo; entity.Bir = model.Bir; entity.Age = model.Age; entity.CreateTime = model.CreateTime; if (Rep.Create(entity) == 1) { return(true); } errors.Add("插入失败"); return(false); } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public bool Edit(ref ValidationErrors errors, SysSampleModel model) { try { SysSample entity = Rep.GetById(model.ID); if (entity == null) { errors.Add("未查到实体"); return(false); } entity = new SysSample(); entity.ID = model.ID; entity.Name = model.Name; entity.Note = model.Note; entity.Photo = model.Photo; entity.Bir = model.Bir; entity.Age = model.Age; entity.CreateTime = model.CreateTime; if (Rep.Edit(entity) > 0) { return(true); } errors.Add("更新失败"); return(false); } catch (Exception ex) { errors.Add(ex.Message); //写入异常 ExceptionHander.WriteException(ex); return(false); } }
public JsonResult Create(FormCollection postedFormData, [System.Web.Http.FromBody] SysSampleMaintenanceDTO sysSampleDTO) { TransactionalInformation transaction; SysSampleMaintenanceViewModel sysSampleMaintenanceViewModel = new SysSampleMaintenanceViewModel(); SysSample sysSample = new SysSample(); ModelStateHelper.UpdateViewModel(sysSampleDTO, sysSample); SysSampleApplicationService sysSampleApplicationService = new SysSampleApplicationService(sysSampleDataService); sysSampleApplicationService.CreateSysSample(sysSample, out transaction); sysSampleMaintenanceViewModel.SysSample = sysSample; sysSampleMaintenanceViewModel.ReturnStatus = transaction.ReturnStatus; sysSampleMaintenanceViewModel.ReturnMessage = transaction.ReturnMessage; sysSampleMaintenanceViewModel.ValidationErrors = transaction.ValidationErrors; //LogHandler logHander = new LogHandler(sysLogDataService); if (transaction.ReturnStatus == false) { //var Json = Request.CreateResponse<CustomerMaintenanceViewModel>(HttpStatusCode.BadRequest, customerMaintenanceViewModel); //return badresponse; //return Json(new //{ // ReturnStatus = sysSampleMaintenanceViewModel.ReturnStatus, // ViewModel = sysSampleMaintenanceViewModel, // ValidationErrors = sysSampleMaintenanceViewModel.ValidationErrors, // //MessageBoxView = Helpers.MvcHelpers.RenderPartialView(this, "_MessageBox", sysSampleMaintenanceViewModel), // //JsonRequestBehavior.AllowGet //}); LogHandler.WriteServiceLog("虚拟用户", "Id:" + sysSample.Id + ",Name:" + sysSample.Name, "失败", "创建", "样例程序"); return(Json(JsonHandler.CreateMessage(0, "插入失败" + sysSampleMaintenanceViewModel.ReturnMessage), JsonRequestBehavior.AllowGet)); //return Json(0, JsonRequestBehavior.AllowGet); } else { //var response = Request.CreateResponse<CustomerMaintenanceViewModel>(HttpStatusCode.Created, customerMaintenanceViewModel); //return response; //return Json(new //{ // ReturnStatus = sysSampleMaintenanceViewModel.ReturnStatus, // ViewModel = sysSampleMaintenanceViewModel, // ValidationErrors = sysSampleMaintenanceViewModel.ValidationErrors, // //MessageBoxView = Helpers.MvcHelpers.RenderPartialView(this, "_MessageBox", sysSampleMaintenanceViewModel), // JsonRequestBehavior.AllowGet //}); LogHandler.WriteServiceLog("虚拟用户", "Id:" + sysSample.Id + ",Name:" + sysSample.Name, "成功", "创建", "样例程序"); return(Json(JsonHandler.CreateMessage(1, "插入成功"), JsonRequestBehavior.AllowGet)); //return Json(1, JsonRequestBehavior.AllowGet); } }
/// <summary> /// 修改一个实体 /// </summary> /// <param name="entity">实体</param> /// <returns></returns> public bool Edit(SysSampleModel model) { try { SysSample entity = sampleRepository.GetEntityById(model.Id); if (entity == null) { return(false); } entity.Name = model.Name; entity.Age = model.Age; entity.Bir = model.Bir; entity.Photo = model.Photo; entity.Note = model.Note; entity.CreateTime = model.CreateTime; if (sampleRepository.Edit(entity) == 1)//成功 { return(true); } else { return(false); } } catch (Exception) { return(false); } }
/// <summary> /// Get SysSample By SysSample ID /// </summary> /// <param name="sysSampleID"></param> /// <returns></returns> public SysSample GetSysSampleById(string sysSampleID) { SysSample sysSample = new SysSample(); string sql = "SELECT * FROM SysSample WHERE Id = '" + sysSampleID.ToString() + "'"; SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = dbConnection; sqlCommand.CommandText = sql; SqlDataReader reader = sqlCommand.ExecuteReader(); if (reader.Read()) { DataReader dataReader = new DataReader(reader); sysSample.Id = dataReader.GetString("Id"); sysSample.Name = dataReader.GetString("Name"); sysSample.Age = dataReader.GetString("Age"); sysSample.Bir = dataReader.GetString("Bir"); sysSample.Photo = dataReader.GetString("Photo"); sysSample.Note = dataReader.GetString("Note"); sysSample.CreateTime = dataReader.GetDateTime("CreateTime"); } reader.Close(); return(sysSample); }
/// <summary> /// Edit model /// </summary> /// <param name="model">model</param> /// <returns>true or false</returns> public bool Edit(SysSampleModel model) { try { SysSample entity = Rep.GetById(model.Id); if (entity == null) { return(false); } entity.Name = model.Name; entity.Age = model.Age; entity.Bir = model.Bir; entity.Photo = model.Photo; entity.Note = model.Note; if (Rep.Edit(entity) == 1) { return(true); } else { return(false); } } catch (Exception ex) { //ExceptionHander.WriteException(ex); return(false); } }
public override bool Create(ref ValidationErrors errors, SysSampleModel model) { try { SysSample entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Suggestion.PrimaryRepeat); return(false); } entity = new SysSample(); entity.Id = model.Id; entity.Name = model.Name.TrimStart(); entity.Age = model.Age; entity.Bir = model.Bir; entity.Photo = model.Photo; entity.Note = model.Note; entity.CreateTime = model.CreateTime; if (m_Rep.Create(entity)) { return(true); } else { errors.Add(Suggestion.InsertFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
/// <summary> /// 创建一个实体 /// </summary> /// <param name="db">数据库上下文</param> /// <param name="entity">实体</param> public int Create(SysSample entity) { DBContainer db = new DBContainer(); db.SysSample.Add(entity); return(db.SaveChanges()); }
//public bool Create(SysSampleModel model) //{ // try // { // var entity = Rep.GetById(model.Id); // if (entity != null) // return false; // entity = new SysSample(); // entity.Id = model.Id; // entity.Name = model.Name; // entity.Age = model.Age; // entity.BirthDay = model.BirthDay; // entity.Photo = model.Photo; // entity.Note = model.Note; // entity.CreateTime = Convert.ToDateTime(model.CreateTime); // if (Rep.Create(entity) == 1) // { // return true; // } // else // { // return false; // } // } // catch (Exception ex) // { // return false; // } //} #endregion public bool Create(ref ValidationErrors errors, SysSampleModel model) { try { SysSample entity = new SysSample(); entity.Name = model.Name; entity.Age = model.Age; entity.Bir = model.BirthDay; entity.Photo = model.Photo; entity.Note = model.Note; entity.CreateTime = DateTime.Now; if (Rep.Create(entity) == 1) { return(true); } else { errors.Add("插入失败"); return(false); } } catch (Exception ex) { errors.Add(ex.Message); BLL.Core.ExceptionHander.WriteException(ex); return(false); } }
/// <summary> /// 修改一个实体 /// </summary> /// <param name="errors">持久的错误信息</param> /// <param name="model">模型</param> /// <returns>是否成功</returns> public bool Edit(ref ValidationErrors errors, SysSampleModel model) { try { SysSample entity = Rep.GetById(model.Id); if (entity == null) { errors.Add("主键不存在"); return(false); } entity.Name = model.Name; entity.Age = model.Age; entity.Bir = model.Bir; entity.Photo = model.Photo; entity.Note = model.Note; if (Rep.Edit(entity) == 1) { return(true); } else { errors.Add("编辑失败"); return(false); } } catch (Exception ex) { errors.Add("编辑异常"); ExceptionHandler.WriteException(ex); return(false); } }
public virtual bool Edit(ref ValidationErrors errors, SysSampleModel model) { try { SysSample entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.Name = model.Name; entity.Age = model.Age; entity.Bir = model.Bir; entity.Photo = model.Photo; entity.Note = model.Note; entity.CreateTime = model.CreateTime; if (m_Rep.Edit(entity)) { return(true); } else { errors.Add("没有数据改变"); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public int Create(SysSample entity) { using (SysMgr_DBEntities db = new SysMgr_DBEntities()) { db.SysSample.Add(entity); return(db.SaveChanges()); } }
public int Edit(SysSample entity) { using (DBContainer db = new DBContainer()) { db.Entry(entity).State = EntityState.Modified; return(db.SaveChanges()); } }
/// <summary> /// 添加一个实体 /// </summary> /// <param name="entity">实体</param> /// <returns></returns> public int Create(SysSample entity) { using (AppsDBEntities db = new AppsDBEntities()) { db.Set <SysSample>().Add(entity); return(db.SaveChanges()); } }
/// <summary> /// 创建一个实体 ///</summary> /// <param name="db">数据库上下文</param> /// <param name="entity">实体</param> public int Create(SysSample entity) { using (AppDBContainer db = new AppDBContainer()) { db.Set <SysSample>().Add(entity); return(db.SaveChanges()); } }
public int Create(SysSample entity) { using (DbContainer db = new DbContainer()) { db.SysSample.Add(entity); return db.SaveChanges(); } }
/// <summary> /// 修改一个实体 /// </summary> /// <param name="db">数据库上下文</param> /// <param name="entity">实体</param> public int Edit(SysSample entity) { DBContainer db = new DBContainer(); db.Entry(entity).State = System.Data.Entity.EntityState.Modified; //db.SysSample.Attach(entity); return(db.SaveChanges()); }
/// <summary> /// 创建一个实体 /// </summary> /// <param name="db">数据库上下文</param> /// <param name="entity">实体</param> public int Create(SysSample entity) { using (DBContainer db = new DBContainer()) { db.SysSample.AddObject(entity); return(db.SaveChanges()); } }
public ActionResult DeleteConfirmed(string id) { SysSample sysSample = db.SysSample.Find(id); db.SysSample.Remove(sysSample); db.SaveChanges(); return(RedirectToAction("Index")); }
/// <summary> /// 修改一个实体 /// /// </summary> /// <param name="db">数据库上下文</param> /// <param name="entity">实体</param> public int Edit(SysSample entity) { using (DBContainer db = new DBContainer()) { //db.Set<entity>().Attach(entity); db.Entry <SysSample>(entity).State = EntityState.Modified; return(db.SaveChanges()); } }
/// <summary> /// 删除一个实体 ///</summary> /// <param name="db">数据库上下文</param> /// <param name="entity">主键ID</param> public int Delete(string id) { using (DBContainer db = new DBContainer()) { SysSample entity = db.SysSample.SingleOrDefault(a => a.Id == id); db.Set <SysSample>().Remove(entity); return(Convert.ToInt32(db.SaveChanges() > 0)); } }
public int Delete(string id) { using (DB db = new DB()) { SysSample entity = db.SysSample.SingleOrDefault(a => a.Id == id); db.Set <SysSample>().Remove(entity); return(db.SaveChanges()); } }
/// <summary> /// 修改一个实体 /// </summary> /// <param name="db">数据库上下文</param> /// <param name="entity">实体</param> public int Edit(SysSample entity) { using (DBContainer db = new DBContainer()) { db.SysSample.Attach(entity); db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); return(db.SaveChanges()); } }
/// <summary> /// 删除一个实体 ///</summary> /// <param name="db">数据库上下文</param> /// <param name="entity">主键ID</param> public bool Delete(string id) { using (DBContainer db = new DBContainer()) { SysSample entity = db.SysSample.SingleOrDefault(a => a.Id.ToString() == id); db.Set <SysSample>().Remove(entity); return(db.SaveChanges() > 0); } }