Beispiel #1
0
        public bool Create(RAW data)
        {
            bool result = false;

            try
            {
                if (IsNotNull(data))
                {
                    string loginname = DungLH.Util.Token.Backend.BackendTokenManager.GetLoginname();
                    CreatorDecorator.Set <RAW>(data, loginname);
                    DummyDecorator.Set <RAW>(data);

                    using (var ctx = new AppContext())
                    {
                        ctx.GetDbSet <RAW>().Add(data);
                        result = (ctx.SaveChanges() > 0);
                    }
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                Logging(LogUtil.TraceDbException(ex), LogType.Error);
                Logging(DungLH.Util.CommonLogging.LogUtil.TraceData("data", data), LogType.Error);
                LogSystem.Error(ex);
                result = false;
            }
            catch (Exception ex)
            {
                Logging(DungLH.Util.CommonLogging.LogUtil.TraceData("data", data), LogType.Error);
                LogSystem.Error(ex);
                result = false;
            }

            return(result);
        }
Beispiel #2
0
        public bool CreateList(List <RAW> listData)
        {
            bool result = false;

            try
            {
                if (IsNotNullOrEmpty(listData))
                {
                    string loginName = DungLH.Util.Token.Backend.BackendTokenManager.GetLoginname();

                    using (var ctx = new AppContext())
                    {
                        var dbSet = ctx.GetDbSet <RAW>();
                        foreach (var data in listData)
                        {
                            CreatorDecorator.Set <RAW>(data, loginName);
                            DummyDecorator.Set <RAW>(data);

                            dbSet.Add(data);
                        }
                        result = (ctx.SaveChanges() > 0);
                    }
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                Logging(LogUtil.TraceDbException(ex), LogType.Error);
                Logging(Newtonsoft.Json.JsonConvert.SerializeObject(listData), LogType.Error);
                LogSystem.Error(ex);
                result = false;
            }
            catch (Exception ex)
            {
                Logging(Newtonsoft.Json.JsonConvert.SerializeObject(listData), LogType.Error);
                LogSystem.Error(ex);
                result = false;
            }
            return(result);
        }