Example #1
0
        public DataSourceResult WHS_Maintain_Hold_Create(IEnumerable <WHS_Maintain_Hold> items, string CreatedBy)
        {
            string WHS_Maintain_Hold_List             = string.Empty;
            string WHS_Maintain_Hold_List_Serialized  = string.Empty;
            string WHS_Maintain_Hold_Items_Serialized = string.Empty;

            string message = string.Empty;
            List <WHS_Maintain_Hold> result = new List <WHS_Maintain_Hold>();

            try
            {
                WMS.Models.DBContext model = new DBContext();
                foreach (WHS_Maintain_Hold item in items)
                {
                    WHS_Maintain_Hold dbItem = new WHS_Maintain_Hold();

                    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.Date_Off      = item.Date_Off;
                    dbItem.Date_On       = item.Date_On;
                    dbItem.Holdreason_ID = item.Holdreason_ID;
                    dbItem.ID            = item.ID;
                    dbItem.IsDeleted     = item.IsDeleted;
                    dbItem.Item_ID       = item.Item_ID;
                    dbItem.Location_ID   = item.Location_ID;
                    dbItem.Lot_ID        = item.Lot_ID;
                    dbItem.ModifiedBy    = item.ModifiedBy;
                    dbItem.ModifiedDate  = item.ModifiedDate;
                    dbItem.User_ID       = item.User_ID;

                    WHS_Maintain_Hold_Items_Serialized += Common.SerializeObject(item);
                    model.DBSet_WHS_Maintain_Hold.Add(dbItem);
                    Common.SaveChanges(model);

                    item.ID = dbItem.ID;
                    WHS_Maintain_Hold_List += "[" + item.ID + "] ";

                    result.Add(item);
                    WHS_Maintain_Hold_List_Serialized += Common.SerializeObject(item);
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
                Common.log.Error(WHS_Maintain_Hold_Items_Serialized, ex);
            }
            finally
            {
                if (!string.IsNullOrEmpty(message))
                {
                    Common.log.Warn(CreatedBy + " => " + WHS_Maintain_Hold_Items_Serialized, new Exception(message));
                }
                Common.log.Info(string.Format("User: {0} - [end] - WHS_Maintain_Hold_Create: {1} - {2}", CreatedBy, WHS_Maintain_Hold_List, WHS_Maintain_Hold_List_Serialized));
            }
            return(result.ToDataSourceResult(new DataSourceRequest()));
        }
Example #2
0
        public bool WHS_Maintain_Hold_Update(IEnumerable <WHS_Maintain_Hold> items, string ModifiedBy)
        {
            string WHS_Maintain_Hold_List             = string.Empty;
            string WHS_Maintain_Hold_List_Serialized  = string.Empty;
            string WHS_Maintain_Hold_Items_Serialized = string.Empty;

            string result = string.Empty;
            bool   flag   = true;

            try
            {
                WMS.Models.DBContext model = new DBContext();
                foreach (WHS_Maintain_Hold item in items)
                {
                    WHS_Maintain_Hold dbItem = model.DBSet_WHS_Maintain_Hold.Where(d => d.ID == item.ID).FirstOrDefault();
                    if (dbItem != null)
                    {
                        WHS_Maintain_Hold_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.Date_Off      = item.Date_Off;
                        dbItem.Date_On       = item.Date_On;
                        dbItem.Holdreason_ID = item.Holdreason_ID;
                        dbItem.ID            = item.ID;
                        dbItem.IsDeleted     = item.IsDeleted;
                        dbItem.Item_ID       = item.Item_ID;
                        dbItem.Location_ID   = item.Location_ID;
                        dbItem.Lot_ID        = item.Lot_ID;
                        dbItem.ModifiedBy    = item.ModifiedBy;
                        dbItem.ModifiedDate  = item.ModifiedDate;
                        dbItem.User_ID       = item.User_ID;


                        WHS_Maintain_Hold_Items_Serialized += Common.SerializeObject(item);
                        Common.SaveChanges(model);
                        WHS_Maintain_Hold_List_Serialized += Common.SerializeObject(item);
                    }
                }
            }
            catch (Exception ex)
            {
                flag   = false;
                result = ex.Message;
                Common.log.Error(WHS_Maintain_Hold_Items_Serialized, ex);
            }
            finally
            {
                if (!string.IsNullOrEmpty(result))
                {
                    Common.log.Warn(ModifiedBy + " => " + WHS_Maintain_Hold_Items_Serialized, new Exception(result));
                }
                Common.log.Info(string.Format("User: {0} - [end] - WHS_Maintain_Hold_Update: {1} - {2}", ModifiedBy, WHS_Maintain_Hold_List, WHS_Maintain_Hold_List_Serialized));
            }
            return(flag);
        }