public DataSourceResult ENT_CycleClass_Create(IEnumerable <ENT_CycleClass> items, string CreatedBy) { string ENT_CycleClass_List = string.Empty; string ENT_CycleClass_List_Serialized = string.Empty; string ENT_CycleClass_Items_Serialized = string.Empty; string message = string.Empty; List <ENT_CycleClass> result = new List <ENT_CycleClass>(); try { WMS.Models.DBContext model = new DBContext(); foreach (ENT_CycleClass item in items) { ENT_CycleClass dbItem = new ENT_CycleClass(); item.CreatedBy = item.ModifiedBy = CreatedBy; item.CreatedDate = item.ModifiedDate = Common.getUTCDate(); dbItem.IsSelected = item.IsSelected; dbItem.TagStr = item.TagStr; dbItem.CreatedBy = item.CreatedBy; dbItem.CreatedDate = item.CreatedDate; dbItem.Cycle_Class_Code = item.Cycle_Class_Code; dbItem.Days = item.Days; dbItem.Description = item.Description; dbItem.ID = item.ID; dbItem.IsDeleted = item.IsDeleted; dbItem.ModifiedBy = item.ModifiedBy; dbItem.ModifiedDate = item.ModifiedDate; dbItem.Percent_Negative_Variance = item.Percent_Negative_Variance; dbItem.Percent_Positive_Variance = item.Percent_Positive_Variance; dbItem.Value_Negative_Variance = item.Value_Negative_Variance; dbItem.Value_Positive_Variance = item.Value_Positive_Variance; ENT_CycleClass_Items_Serialized += Common.SerializeObject(item); model.DBSet_ENT_CycleClass.Add(dbItem); Common.SaveChanges(model); item.ID = dbItem.ID; ENT_CycleClass_List += "[" + item.ID + "] "; result.Add(item); ENT_CycleClass_List_Serialized += Common.SerializeObject(item); } } catch (Exception ex) { message = ex.Message; Common.log.Error(ENT_CycleClass_Items_Serialized, ex); } finally { if (!string.IsNullOrEmpty(message)) { Common.log.Warn(CreatedBy + " => " + ENT_CycleClass_Items_Serialized, new Exception(message)); } Common.log.Info(string.Format("User: {0} - [end] - ENT_CycleClass_Create: {1} - {2}", CreatedBy, ENT_CycleClass_List, ENT_CycleClass_List_Serialized)); } return(result.ToDataSourceResult(new DataSourceRequest())); }
public bool ENT_CycleClass_Update(IEnumerable <ENT_CycleClass> items, string ModifiedBy) { string ENT_CycleClass_List = string.Empty; string ENT_CycleClass_List_Serialized = string.Empty; string ENT_CycleClass_Items_Serialized = string.Empty; string result = string.Empty; bool flag = true; try { WMS.Models.DBContext model = new DBContext(); foreach (ENT_CycleClass item in items) { ENT_CycleClass dbItem = model.DBSet_ENT_CycleClass.Where(d => d.ID == item.ID).FirstOrDefault(); if (dbItem != null) { ENT_CycleClass_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.CreatedBy = item.CreatedBy; dbItem.CreatedDate = item.CreatedDate; dbItem.Cycle_Class_Code = item.Cycle_Class_Code; dbItem.Days = item.Days; dbItem.Description = item.Description; dbItem.ID = item.ID; dbItem.IsDeleted = item.IsDeleted; dbItem.ModifiedBy = item.ModifiedBy; dbItem.ModifiedDate = item.ModifiedDate; dbItem.Percent_Negative_Variance = item.Percent_Negative_Variance; dbItem.Percent_Positive_Variance = item.Percent_Positive_Variance; dbItem.Value_Negative_Variance = item.Value_Negative_Variance; dbItem.Value_Positive_Variance = item.Value_Positive_Variance; ENT_CycleClass_Items_Serialized += Common.SerializeObject(item); Common.SaveChanges(model); ENT_CycleClass_List_Serialized += Common.SerializeObject(item); } } } catch (Exception ex) { flag = false; result = ex.Message; Common.log.Error(ENT_CycleClass_Items_Serialized, ex); } finally { if (!string.IsNullOrEmpty(result)) { Common.log.Warn(ModifiedBy + " => " + ENT_CycleClass_Items_Serialized, new Exception(result)); } Common.log.Info(string.Format("User: {0} - [end] - ENT_CycleClass_Update: {1} - {2}", ModifiedBy, ENT_CycleClass_List, ENT_CycleClass_List_Serialized)); } return(flag); }