public void SaveEditData(IEnumerable <Spl_WarehouseWarrantDetailsModel> personList, string warehouseWarrantId) { try { using (DBContainer db = new DBContainer()) { int count = db.Database.ExecuteSqlCommand("delete Spl_WarehouseWarrantDetails where WarehouseWarrantId=@WarehouseWarrantId", new SqlParameter("@WarehouseWarrantId", warehouseWarrantId)); foreach (var model in personList) { Spl_WarehouseWarrantDetails entity = new Spl_WarehouseWarrantDetails(); entity.Id = model.Id; entity.WareDetailsId = model.WareDetailsId; entity.WarehouseId = model.WarehouseId; entity.WarehouseWarrantId = model.WarehouseWarrantId; entity.Quantity = model.Quantity; entity.Price = model.Price; entity.TotalPrice = model.TotalPrice; entity.Defined = model.Defined; entity.CreateTime = model.CreateTime; entity.Id = ResultHelper.NewId; db.Spl_WarehouseWarrantDetails.Add(entity); } db.SaveChanges(); } } catch { throw; } }
/// <summary> /// 保存数据 /// </summary> public virtual void SaveImportData(IEnumerable<Spl_WarehouseWarrantDetailsModel> list) { try { using (DBContainer db = new DBContainer()) { foreach (var model in list) { Spl_WarehouseWarrantDetails entity = new Spl_WarehouseWarrantDetails(); entity.Id = ResultHelper.NewId; entity.WareDetailsId = model.WareDetailsId; entity.WarehouseId = model.WarehouseId; entity.WarehouseWarrantId = model.WarehouseWarrantId; entity.Quantity = model.Quantity; entity.Price = model.Price; entity.TotalPrice = model.TotalPrice; entity.Defined = model.Defined; entity.CreateTime = ResultHelper.NowTime; db.Spl_WarehouseWarrantDetails.Add(entity); } db.SaveChanges(); } } catch(Exception ex) { throw; } }
public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_WarehouseWarrantDetailsModel model) { ValidationErrors errors = new ValidationErrors(); try { Spl_WarehouseWarrantDetails entity = await m_Rep.GetByIdAsync(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(new Tuple <ValidationErrors, bool>(errors, false)); } entity = new Spl_WarehouseWarrantDetails(); entity.Id = model.Id; entity.WareDetailsId = model.WareDetailsId; entity.WarehouseId = model.WarehouseId; entity.WarehouseWarrantId = model.WarehouseWarrantId; entity.Quantity = model.Quantity; entity.Price = model.Price; entity.TotalPrice = model.TotalPrice; entity.Defined = model.Defined; entity.CreateTime = model.CreateTime; 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 virtual bool Edit(ref ValidationErrors errors, Spl_WarehouseWarrantDetailsModel model) { try { Spl_WarehouseWarrantDetails entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return false; } entity.Id = model.Id; entity.WareDetailsId = model.WareDetailsId; entity.WarehouseId = model.WarehouseId; entity.WarehouseWarrantId = model.WarehouseWarrantId; entity.Quantity = model.Quantity; entity.Price = model.Price; entity.TotalPrice = model.TotalPrice; entity.Defined = model.Defined; entity.CreateTime = model.CreateTime; 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; } }
public virtual bool Create(ref ValidationErrors errors, Spl_WarehouseWarrantDetailsModel model) { try { Spl_WarehouseWarrantDetails entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return false; } entity = new Spl_WarehouseWarrantDetails(); entity.Id = model.Id; entity.WareDetailsId = model.WareDetailsId; entity.WarehouseId = model.WarehouseId; entity.WarehouseWarrantId = model.WarehouseWarrantId; entity.Quantity = model.Quantity; entity.Price = model.Price; entity.TotalPrice = model.TotalPrice; entity.Defined = model.Defined; entity.CreateTime = model.CreateTime; 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; } }
/// <summary> /// 保存数据 /// </summary> public void SaveData(IEnumerable <Spl_WarehouseWarrantDetailsModel> personList) { try { using (DBContainer db = new DBContainer()) { foreach (var model in personList) { Spl_WarehouseWarrantDetails entity = new Spl_WarehouseWarrantDetails(); entity.Id = model.Id; entity.WareDetailsId = model.WareDetailsId; entity.WarehouseId = model.WarehouseId; entity.WarehouseWarrantId = model.WarehouseWarrantId; entity.Quantity = model.Quantity; entity.Price = model.Price; entity.TotalPrice = model.TotalPrice; entity.Defined = model.Defined; entity.CreateTime = model.CreateTime; //新增 if (string.IsNullOrEmpty(model.Id)) { entity.Id = ResultHelper.NewId; db.Spl_WarehouseWarrantDetails.Add(entity); } else { //修改 db.Set <Spl_WarehouseWarrantDetails>().Attach(entity); db.Entry <Spl_WarehouseWarrantDetails>(entity).State = EntityState.Modified; } } db.SaveChanges(); } } catch { throw; } }
public virtual Spl_WarehouseWarrantDetailsModel GetById(object id) { if (IsExists(id)) { Spl_WarehouseWarrantDetails entity = m_Rep.GetById(id); Spl_WarehouseWarrantDetailsModel model = new Spl_WarehouseWarrantDetailsModel(); model.Id = entity.Id; model.WareDetailsId = entity.WareDetailsId; model.WarehouseId = entity.WarehouseId; model.WarehouseWarrantId = entity.WarehouseWarrantId; model.Quantity = entity.Quantity; model.Price = entity.Price; model.TotalPrice = entity.TotalPrice; model.Defined = entity.Defined; model.CreateTime = entity.CreateTime; return model; } else { return null; } }
public virtual async Task <Spl_WarehouseWarrantDetailsModel> GetByIdAsync(object id) { if (IsExists(id)) { Spl_WarehouseWarrantDetails entity = await m_Rep.GetByIdAsync(id); Spl_WarehouseWarrantDetailsModel model = new Spl_WarehouseWarrantDetailsModel(); model.Id = entity.Id; model.WareDetailsId = entity.WareDetailsId; model.WarehouseId = entity.WarehouseId; model.WarehouseWarrantId = entity.WarehouseWarrantId; model.Quantity = entity.Quantity; model.Price = entity.Price; model.TotalPrice = entity.TotalPrice; model.Defined = entity.Defined; model.CreateTime = entity.CreateTime; return(model); } else { return(null); } }