public bool WHS_ASN_Update(IEnumerable <WHS_ASN> items, string ModifiedBy) { string WHS_ASN_List = string.Empty; string WHS_ASN_List_Serialized = string.Empty; string WHS_ASN_Items_Serialized = string.Empty; string result = string.Empty; bool flag = true; try { WMS.Models.DBContext model = new DBContext(); foreach (WHS_ASN item in items) { WHS_ASN dbItem = model.DBSet_WHS_ASN.Where(d => d.ID == item.ID).FirstOrDefault(); if (dbItem != null) { WHS_ASN_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.Actual_receipt_date = item.Actual_receipt_date; dbItem.ASN_Code = item.ASN_Code; dbItem.Carrier_ID = item.Carrier_ID; dbItem.CreatedBy = item.CreatedBy; dbItem.CreatedDate = item.CreatedDate; dbItem.Date_created = item.Date_created; dbItem.Expected_cube = item.Expected_cube; dbItem.Expected_weight = item.Expected_weight; dbItem.External_receipt = item.External_receipt; dbItem.ID = item.ID; dbItem.IsDeleted = item.IsDeleted; dbItem.ModifiedBy = item.ModifiedBy; dbItem.ModifiedDate = item.ModifiedDate; dbItem.Note = item.Note; dbItem.ReceiptStatus_ID = item.ReceiptStatus_ID; dbItem.Schedule_receipt_date = item.Schedule_receipt_date; dbItem.Supplier_ID = item.Supplier_ID; dbItem.Total_Expected_Qty = item.Total_Expected_Qty; dbItem.Total_Receipted_Qty = item.Total_Receipted_Qty; WHS_ASN_Items_Serialized += Common.SerializeObject(item); Common.SaveChanges(model); WHS_ASN_List_Serialized += Common.SerializeObject(item); } } } catch (Exception ex) { flag = false; result = ex.Message; Common.log.Error(WHS_ASN_Items_Serialized, ex); } finally { if (!string.IsNullOrEmpty(result)) { Common.log.Warn(ModifiedBy + " => " + WHS_ASN_Items_Serialized, new Exception(result)); } Common.log.Info(string.Format("User: {0} - [end] - WHS_ASN_Update: {1} - {2}", ModifiedBy, WHS_ASN_List, WHS_ASN_List_Serialized)); } return(flag); }
public DataSourceResult WHS_ASN_Create(WHS_ASN item, string CreatedBy) { string WHS_ASN_List = string.Empty; string WHS_ASN_List_Serialized = string.Empty; string WHS_ASN_Items_Serialized = string.Empty; string message = string.Empty; List <WHS_ASN> result = new List <WHS_ASN>(); try { WMS.Models.DBContext model = new DBContext(); WHS_ASN dbItem = new WHS_ASN(); item.CreatedBy = item.ModifiedBy = CreatedBy; item.CreatedDate = item.ModifiedDate = Common.getUTCDate(); dbItem.IsSelected = item.IsSelected; dbItem.TagStr = item.TagStr; dbItem.Actual_receipt_date = item.Actual_receipt_date; dbItem.ASN_Code = item.ASN_Code; dbItem.Carrier_ID = item.Carrier_ID; dbItem.CreatedBy = item.CreatedBy; dbItem.CreatedDate = item.CreatedDate; dbItem.Date_created = item.Date_created; dbItem.Expected_cube = item.Expected_cube; dbItem.Expected_weight = item.Expected_weight; dbItem.External_receipt = item.External_receipt; dbItem.ID = item.ID; dbItem.IsDeleted = item.IsDeleted; dbItem.ModifiedBy = item.ModifiedBy; dbItem.ModifiedDate = item.ModifiedDate; dbItem.Note = item.Note; dbItem.ReceiptStatus_ID = item.ReceiptStatus_ID; dbItem.Schedule_receipt_date = item.Schedule_receipt_date; dbItem.Supplier_ID = item.Supplier_ID; dbItem.Total_Expected_Qty = item.Total_Expected_Qty; dbItem.Total_Receipted_Qty = item.Total_Receipted_Qty; WHS_ASN_Items_Serialized += Common.SerializeObject(item); model.DBSet_WHS_ASN.Add(dbItem); Common.SaveChanges(model); item.ID = dbItem.ID; WHS_ASN_List += "[" + item.ID + "] "; result.Add(item); WHS_ASN_List_Serialized += Common.SerializeObject(item); } catch (Exception ex) { message = ex.Message; Common.log.Error(WHS_ASN_Items_Serialized, ex); } finally { if (!string.IsNullOrEmpty(message)) { Common.log.Warn(CreatedBy + " => " + WHS_ASN_Items_Serialized, new Exception(message)); } Common.log.Info(string.Format("User: {0} - [end] - WHS_ASN_Create: {1} - {2}", CreatedBy, WHS_ASN_List, WHS_ASN_List_Serialized)); } return(result.ToDataSourceResult(new DataSourceRequest())); }