/// <summary> /// 保存数据 /// </summary> public virtual void SaveImportData(IEnumerable <Spl_ProductModel> list) { try { using (DBContainer db = new DBContainer()) { foreach (var model in list) { Spl_Product entity = new Spl_Product(); entity.Id = ResultHelper.NewId; entity.Name = model.Name; entity.Code = model.Code; entity.Price = model.Price; entity.CostPrice = model.CostPrice; entity.Color = model.Color; entity.Number = model.Number; entity.CategoryId = model.CategoryId; entity.CreateTime = ResultHelper.NowTime; entity.CreateBy = model.CreateBy; db.Spl_Product.Add(entity); } db.SaveChanges(); } } catch (Exception ex) { throw; } }
public virtual async Task <Spl_ProductModel> GetByIdAsync(object id) { if (IsExists(id)) { Spl_Product entity = await m_Rep.GetByIdAsync(id); Spl_ProductModel model = new Spl_ProductModel(); model.Id = entity.Id; model.Name = entity.Name; model.Code = entity.Code; model.Price = entity.Price; model.Color = entity.Color; model.Number = entity.Number; model.CategoryId = entity.CategoryId; model.CreateTime = entity.CreateTime; model.CreateBy = entity.CreateBy; model.CostPrice = entity.CostPrice; return(model); } else { return(null); } }
public virtual Apps.Models.Spl.Spl_ProductModel GetById(string id) { Spl_Product entity = m_Rep.GetById(id); if (entity != null) { //Spl_Product entity = m_Rep.GetById(id); Apps.Models.Spl.Spl_ProductModel model = new Apps.Models.Spl.Spl_ProductModel(); model.Id = entity.Id; model.Name = entity.Name; model.Code = entity.Code; model.Price = entity.Price; model.CostPrice = entity.CostPrice; model.Color = entity.Color; model.Number = entity.Number; model.CategoryId = entity.CategoryId; model.CreateTime = entity.CreateTime; model.CreateBy = entity.CreateBy; return(model); } else { return(null); } }
public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_ProductModel model) { ValidationErrors errors = new ValidationErrors(); try { Spl_Product entity = await m_Rep.GetByIdAsync(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(new Tuple <ValidationErrors, bool>(errors, false)); } entity = new Spl_Product(); entity.Id = model.Id; entity.Name = model.Name; entity.Code = model.Code; entity.Price = model.Price; entity.Color = model.Color; entity.Number = model.Number; entity.CategoryId = model.CategoryId; entity.CreateTime = model.CreateTime; entity.CreateBy = model.CreateBy; entity.CostPrice = model.CostPrice; if (await m_Rep.CreateAsync(entity)) { return(new Tuple <ValidationErrors, bool>(errors, true)); } else { errors.Add(Resource.InsertFail); return(new Tuple <ValidationErrors, bool>(errors, false)); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(new Tuple <ValidationErrors, bool>(errors, false)); } }
public JsonResult Edit(Spl_Product model) { if (model != null && ModelState.IsValid) { if (m_BLL.m_Rep.Update(model)) { LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "修改", "Spl_Product"); return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed))); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "修改", "Spl_Product"); return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol))); } } else { return(Json(JsonHandler.CreateMessage(0, Resource.EditFail))); } }
public virtual bool Create(ref ValidationErrors errors, Spl_ProductModel model) { try { Spl_Product entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(false); } entity = new Spl_Product(); entity.Id = model.Id; entity.Name = model.Name; entity.Code = model.Code; entity.Price = model.Price; entity.CostPrice = model.CostPrice; entity.Color = model.Color; entity.Number = model.Number; entity.CategoryId = model.CategoryId; entity.CreateTime = model.CreateTime; entity.CreateBy = model.CreateBy; if (m_Rep.Create(entity)) { return(true); } else { errors.Add(Resource.InsertFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public virtual bool Edit(ref ValidationErrors errors, Spl_ProductModel model) { try { Spl_Product entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.Name = model.Name; entity.Code = model.Code; entity.Price = model.Price; entity.CostPrice = model.CostPrice; entity.Color = model.Color; entity.Number = model.Number; entity.CategoryId = model.CategoryId; entity.CreateTime = model.CreateTime; entity.CreateBy = model.CreateBy; if (m_Rep.Edit(entity)) { return(true); } else { errors.Add(Resource.NoDataChange); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
//[SupportFilter] public JsonResult Create(Spl_Product model) { model.CreateTime = ResultHelper.NowTime.ToString("yyyy-MM-dd HH:mm:ss"); if (model != null && ModelState.IsValid) { if (m_BLL.m_Rep.Create(model)) { LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "创建", "Spl_Product"); return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed))); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "创建", "Spl_Product"); return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ErrorCol))); } } else { return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail))); } }
public virtual void Create(ref ValidationErrors errors, Apps.Models.Spl.Spl_ProductModel model) { Spl_Product entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return; } entity = new Spl_Product(); entity.Id = model.Id; entity.Name = model.Name; entity.Code = model.Code; entity.Price = model.Price; entity.CostPrice = model.CostPrice; entity.Color = model.Color; entity.Number = model.Number; entity.CategoryId = model.CategoryId; entity.CreateTime = model.CreateTime; entity.CreateBy = model.CreateBy; m_Rep.Create(entity); }
public virtual void Modify(ref ValidationErrors errors, Apps.Models.Spl.Spl_ProductModel model, params string[] updateProperties) { Spl_Product 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.Code = model.Code; entity.Price = model.Price; entity.CostPrice = model.CostPrice; entity.Color = model.Color; entity.Number = model.Number; entity.CategoryId = model.CategoryId; entity.CreateTime = model.CreateTime; entity.CreateBy = model.CreateBy; } else { Type type = typeof(Apps.Models.Spl.Spl_ProductModel); Type typeE = typeof(Apps.Models.Spl_Product); 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 virtual Spl_ProductModel GetById(string id) { if (IsExists(id)) { Spl_Product entity = m_Rep.GetById(id); Spl_ProductModel model = new Spl_ProductModel(); model.Id = entity.Id; model.Name = entity.Name; model.Code = entity.Code; model.Price = entity.Price; model.Color = entity.Color; model.Number = entity.Number; model.CategoryId = entity.CategoryId; model.CreateTime = entity.CreateTime; model.CreateBy = entity.CreateBy; model.CostPrice = entity.CostPrice; return(model); } else { return(null); } }
public ActionResult Details(string id) { Spl_Product entity = m_BLL.m_Rep.Find(Convert.ToInt32(id)); return(View(entity)); }