public DataSourceResult ENT_BOM_Create(IEnumerable <ENT_BOM> items, string CreatedBy) { string ENT_BOM_List = string.Empty; string ENT_BOM_List_Serialized = string.Empty; string ENT_BOM_Items_Serialized = string.Empty; string message = string.Empty; List <ENT_BOM> result = new List <ENT_BOM>(); try { WMS.Models.DBContext model = new DBContext(); foreach (ENT_BOM item in items) { ENT_BOM dbItem = new ENT_BOM(); item.CreatedBy = item.ModifiedBy = CreatedBy; item.CreatedDate = item.ModifiedDate = Common.getUTCDate(); dbItem.IsSelected = item.IsSelected; dbItem.TagStr = item.TagStr; dbItem.Component_ID = item.Component_ID; dbItem.CreatedBy = item.CreatedBy; dbItem.CreatedDate = item.CreatedDate; dbItem.ID = item.ID; dbItem.IsDeleted = item.IsDeleted; dbItem.Item_ID = item.Item_ID; dbItem.ModifiedBy = item.ModifiedBy; dbItem.ModifiedDate = item.ModifiedDate; dbItem.Notes = item.Notes; dbItem.Owner_Code = item.Owner_Code; dbItem.Quantity = item.Quantity; dbItem.Sequence = item.Sequence; ENT_BOM_Items_Serialized += Common.SerializeObject(item); model.DBSet_ENT_BOM.Add(dbItem); Common.SaveChanges(model); item.ID = dbItem.ID; ENT_BOM_List += "[" + item.ID + "] "; result.Add(item); ENT_BOM_List_Serialized += Common.SerializeObject(item); } } catch (Exception ex) { message = ex.Message; Common.log.Error(ENT_BOM_Items_Serialized, ex); } finally { if (!string.IsNullOrEmpty(message)) { Common.log.Warn(CreatedBy + " => " + ENT_BOM_Items_Serialized, new Exception(message)); } Common.log.Info(string.Format("User: {0} - [end] - ENT_BOM_Create: {1} - {2}", CreatedBy, ENT_BOM_List, ENT_BOM_List_Serialized)); } return(result.ToDataSourceResult(new DataSourceRequest())); }
public bool ENT_BOM_Update(IEnumerable <ENT_BOM> items, string ModifiedBy) { string ENT_BOM_List = string.Empty; string ENT_BOM_List_Serialized = string.Empty; string ENT_BOM_Items_Serialized = string.Empty; string result = string.Empty; bool flag = true; try { WMS.Models.DBContext model = new DBContext(); foreach (ENT_BOM item in items) { ENT_BOM dbItem = model.DBSet_ENT_BOM.Where(d => d.ID == item.ID).FirstOrDefault(); if (dbItem != null) { ENT_BOM_List += "[" + item.ID + "] "; item.ModifiedBy = ModifiedBy; item.ModifiedDate = Common.getUTCDate(); if (item.CreatedDate == DateTime.MinValue) { item.CreatedDate = dbItem.CreatedDate; } dbItem.IsSelected = item.IsSelected; dbItem.TagStr = item.TagStr; dbItem.Component_ID = item.Component_ID; dbItem.CreatedBy = item.CreatedBy; dbItem.CreatedDate = item.CreatedDate; dbItem.ID = item.ID; dbItem.IsDeleted = item.IsDeleted; dbItem.Item_ID = item.Item_ID; dbItem.ModifiedBy = item.ModifiedBy; dbItem.ModifiedDate = item.ModifiedDate; dbItem.Notes = item.Notes; dbItem.Owner_Code = item.Owner_Code; dbItem.Quantity = item.Quantity; dbItem.Sequence = item.Sequence; ENT_BOM_Items_Serialized += Common.SerializeObject(item); Common.SaveChanges(model); ENT_BOM_List_Serialized += Common.SerializeObject(item); } } } catch (Exception ex) { flag = false; result = ex.Message; Common.log.Error(ENT_BOM_Items_Serialized, ex); } finally { if (!string.IsNullOrEmpty(result)) { Common.log.Warn(ModifiedBy + " => " + ENT_BOM_Items_Serialized, new Exception(result)); } Common.log.Info(string.Format("User: {0} - [end] - ENT_BOM_Update: {1} - {2}", ModifiedBy, ENT_BOM_List, ENT_BOM_List_Serialized)); } return(flag); }