Example #1
0
        public DataSourceResult WHS_Owner_Label_Create(IEnumerable <WHS_Owner_Label> items, string CreatedBy)
        {
            string WHS_Owner_Label_List             = string.Empty;
            string WHS_Owner_Label_List_Serialized  = string.Empty;
            string WHS_Owner_Label_Items_Serialized = string.Empty;

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

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

                    item.CreatedBy         = item.ModifiedBy = CreatedBy;
                    item.CreatedDate       = item.ModifiedDate = Common.getUTCDate();
                    dbItem.IsSelected      = item.IsSelected;
                    dbItem.TagStr          = item.TagStr;
                    dbItem.Case_Label_Type = item.Case_Label_Type;
                    dbItem.CreatedBy       = item.CreatedBy;
                    dbItem.CreatedDate     = item.CreatedDate;
                    dbItem.ID                 = item.ID;
                    dbItem.IsDeleted          = item.IsDeleted;
                    dbItem.LPN_Barcode_Format = item.LPN_Barcode_Format;
                    dbItem.LPN_Length         = item.LPN_Length;
                    dbItem.LPN_Next_Number    = item.LPN_Next_Number;
                    dbItem.LPN_Start_Number   = item.LPN_Start_Number;
                    dbItem.ModifiedBy         = item.ModifiedBy;
                    dbItem.ModifiedDate       = item.ModifiedDate;
                    dbItem.Owner_ID           = item.Owner_ID;
                    dbItem.Roll_Back_Number   = item.Roll_Back_Number;

                    WHS_Owner_Label_Items_Serialized += Common.SerializeObject(item);
                    model.DBSet_WHS_Owner_Label.Add(dbItem);
                    Common.SaveChanges(model);

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

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

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

            try
            {
                WMS.Models.DBContext model = new DBContext();
                foreach (WHS_Owner_Label item in items)
                {
                    WHS_Owner_Label dbItem = model.DBSet_WHS_Owner_Label.Where(d => d.ID == item.ID).FirstOrDefault();
                    if (dbItem != null)
                    {
                        WHS_Owner_Label_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.Case_Label_Type = item.Case_Label_Type;
                        dbItem.CreatedBy       = item.CreatedBy;
                        dbItem.CreatedDate     = item.CreatedDate;
                        dbItem.ID                 = item.ID;
                        dbItem.IsDeleted          = item.IsDeleted;
                        dbItem.LPN_Barcode_Format = item.LPN_Barcode_Format;
                        dbItem.LPN_Length         = item.LPN_Length;
                        dbItem.LPN_Next_Number    = item.LPN_Next_Number;
                        dbItem.LPN_Start_Number   = item.LPN_Start_Number;
                        dbItem.ModifiedBy         = item.ModifiedBy;
                        dbItem.ModifiedDate       = item.ModifiedDate;
                        dbItem.Owner_ID           = item.Owner_ID;
                        dbItem.Roll_Back_Number   = item.Roll_Back_Number;


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