public bool ENT_Customer_Update(IEnumerable <ENT_Customer> items, string ModifiedBy) { string ENT_Customer_List = string.Empty; string ENT_Customer_List_Serialized = string.Empty; string ENT_Customer_Items_Serialized = string.Empty; string result = string.Empty; bool flag = true; try { WMS.Models.DBContext model = new DBContext(); foreach (ENT_Customer item in items) { ENT_Customer dbItem = model.DBSet_ENT_Customer.Where(d => d.ID == item.ID).FirstOrDefault(); if (dbItem != null) { ENT_Customer_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.Address = item.Address; dbItem.Billing_Address = item.Billing_Address; dbItem.Billing_City = item.Billing_City; dbItem.Billing_District = item.Billing_District; dbItem.Billing_Email1 = item.Billing_Email1; dbItem.Billing_Email2 = item.Billing_Email2; dbItem.Billing_Fax1 = item.Billing_Fax1; dbItem.Billing_Fax2 = item.Billing_Fax2; dbItem.Billing_Phone1 = item.Billing_Phone1; dbItem.Billing_Phone2 = item.Billing_Phone2; dbItem.City = item.City; dbItem.Company = item.Company; dbItem.CreatedBy = item.CreatedBy; dbItem.CreatedDate = item.CreatedDate; dbItem.Customer_Code = item.Customer_Code; dbItem.District = item.District; dbItem.Email1 = item.Email1; dbItem.Email2 = item.Email2; dbItem.Fax1 = item.Fax1; dbItem.Fax2 = item.Fax2; dbItem.ID = item.ID; dbItem.IsDeleted = item.IsDeleted; dbItem.ModifiedBy = item.ModifiedBy; dbItem.ModifiedDate = item.ModifiedDate; dbItem.Notes = item.Notes; dbItem.Owner_ID = item.Owner_ID; dbItem.Phone1 = item.Phone1; dbItem.Phone2 = item.Phone2; dbItem.UDF_1 = item.UDF_1; dbItem.UDF_2 = item.UDF_2; dbItem.UDF_3 = item.UDF_3; dbItem.UDF_4 = item.UDF_4; dbItem.UDF_5 = item.UDF_5; ENT_Customer_Items_Serialized += Common.SerializeObject(item); Common.SaveChanges(model); ENT_Customer_List_Serialized += Common.SerializeObject(item); } } } catch (Exception ex) { flag = false; result = ex.Message; Common.log.Error(ENT_Customer_Items_Serialized, ex); } finally { if (!string.IsNullOrEmpty(result)) { Common.log.Warn(ModifiedBy + " => " + ENT_Customer_Items_Serialized, new Exception(result)); } Common.log.Info(string.Format("User: {0} - [end] - ENT_Customer_Update: {1} - {2}", ModifiedBy, ENT_Customer_List, ENT_Customer_List_Serialized)); } return(flag); }
public DataSourceResult ENT_Customer_Create(ENT_Customer item, string CreatedBy) { string ENT_Customer_List = string.Empty; string ENT_Customer_List_Serialized = string.Empty; string ENT_Customer_Items_Serialized = string.Empty; string message = string.Empty; List <ENT_Customer> result = new List <ENT_Customer>(); try { WMS.Models.DBContext model = new DBContext(); ENT_Customer dbItem = new ENT_Customer(); item.CreatedBy = item.ModifiedBy = CreatedBy; item.CreatedDate = item.ModifiedDate = Common.getUTCDate(); dbItem.IsSelected = item.IsSelected; dbItem.TagStr = item.TagStr; dbItem.Address = item.Address; dbItem.Billing_Address = item.Billing_Address; dbItem.Billing_City = item.Billing_City; dbItem.Billing_District = item.Billing_District; dbItem.Billing_Email1 = item.Billing_Email1; dbItem.Billing_Email2 = item.Billing_Email2; dbItem.Billing_Fax1 = item.Billing_Fax1; dbItem.Billing_Fax2 = item.Billing_Fax2; dbItem.Billing_Phone1 = item.Billing_Phone1; dbItem.Billing_Phone2 = item.Billing_Phone2; dbItem.City = item.City; dbItem.Company = item.Company; dbItem.CreatedBy = item.CreatedBy; dbItem.CreatedDate = item.CreatedDate; dbItem.Customer_Code = item.Customer_Code; dbItem.District = item.District; dbItem.Email1 = item.Email1; dbItem.Email2 = item.Email2; dbItem.Fax1 = item.Fax1; dbItem.Fax2 = item.Fax2; dbItem.ID = item.ID; dbItem.IsDeleted = item.IsDeleted; dbItem.ModifiedBy = item.ModifiedBy; dbItem.ModifiedDate = item.ModifiedDate; dbItem.Notes = item.Notes; dbItem.Owner_ID = item.Owner_ID; dbItem.Phone1 = item.Phone1; dbItem.Phone2 = item.Phone2; dbItem.UDF_1 = item.UDF_1; dbItem.UDF_2 = item.UDF_2; dbItem.UDF_3 = item.UDF_3; dbItem.UDF_4 = item.UDF_4; dbItem.UDF_5 = item.UDF_5; ENT_Customer_Items_Serialized += Common.SerializeObject(item); model.DBSet_ENT_Customer.Add(dbItem); Common.SaveChanges(model); item.ID = dbItem.ID; ENT_Customer_List += "[" + item.ID + "] "; result.Add(item); ENT_Customer_List_Serialized += Common.SerializeObject(item); } catch (Exception ex) { message = ex.Message; Common.log.Error(ENT_Customer_Items_Serialized, ex); } finally { if (!string.IsNullOrEmpty(message)) { Common.log.Warn(CreatedBy + " => " + ENT_Customer_Items_Serialized, new Exception(message)); } Common.log.Info(string.Format("User: {0} - [end] - ENT_Customer_Create: {1} - {2}", CreatedBy, ENT_Customer_List, ENT_Customer_List_Serialized)); } return(result.ToDataSourceResult(new DataSourceRequest())); }