コード例 #1
0
        public bool LIST_Code_Update(IEnumerable <LIST_Code> items, string ModifiedBy)
        {
            string LIST_Code_List             = string.Empty;
            string LIST_Code_List_Serialized  = string.Empty;
            string LIST_Code_Items_Serialized = string.Empty;

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

            try
            {
                WMS.Models.DBContext model = new DBContext();
                foreach (LIST_Code item in items)
                {
                    LIST_Code dbItem = model.DBSet_LIST_Code.Where(d => d.ID == item.ID).FirstOrDefault();
                    if (dbItem != null)
                    {
                        LIST_Code_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.Description  = item.Description;
                        dbItem.ID           = item.ID;
                        dbItem.IsDeleted    = item.IsDeleted;
                        dbItem.ModifiedBy   = item.ModifiedBy;
                        dbItem.ModifiedDate = item.ModifiedDate;
                        dbItem.Name         = item.Name;
                        dbItem.Type         = item.Type;


                        LIST_Code_Items_Serialized += Common.SerializeObject(item);
                        Common.SaveChanges(model);
                        LIST_Code_List_Serialized += Common.SerializeObject(item);
                    }
                }
            }
            catch (Exception ex)
            {
                flag   = false;
                result = ex.Message;
                Common.log.Error(LIST_Code_Items_Serialized, ex);
            }
            finally
            {
                if (!string.IsNullOrEmpty(result))
                {
                    Common.log.Warn(ModifiedBy + " => " + LIST_Code_Items_Serialized, new Exception(result));
                }
                Common.log.Info(string.Format("User: {0} - [end] - LIST_Code_Update: {1} - {2}", ModifiedBy, LIST_Code_List, LIST_Code_List_Serialized));
            }
            return(flag);
        }
コード例 #2
0
        public DataSourceResult LIST_Code_Create(IEnumerable <LIST_Code> items, string CreatedBy)
        {
            string LIST_Code_List             = string.Empty;
            string LIST_Code_List_Serialized  = string.Empty;
            string LIST_Code_Items_Serialized = string.Empty;

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

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

                    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.Description  = item.Description;
                    dbItem.ID           = item.ID;
                    dbItem.IsDeleted    = item.IsDeleted;
                    dbItem.ModifiedBy   = item.ModifiedBy;
                    dbItem.ModifiedDate = item.ModifiedDate;
                    dbItem.Name         = item.Name;
                    dbItem.Type         = item.Type;

                    LIST_Code_Items_Serialized += Common.SerializeObject(item);
                    model.DBSet_LIST_Code.Add(dbItem);
                    Common.SaveChanges(model);

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

                    result.Add(item);
                    LIST_Code_List_Serialized += Common.SerializeObject(item);
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
                Common.log.Error(LIST_Code_Items_Serialized, ex);
            }
            finally
            {
                if (!string.IsNullOrEmpty(message))
                {
                    Common.log.Warn(CreatedBy + " => " + LIST_Code_Items_Serialized, new Exception(message));
                }
                Common.log.Info(string.Format("User: {0} - [end] - LIST_Code_Create: {1} - {2}", CreatedBy, LIST_Code_List, LIST_Code_List_Serialized));
            }
            return(result.ToDataSourceResult(new DataSourceRequest()));
        }