/// <summary>
        /// 保存数据
        /// </summary>
        public virtual void SaveImportData(IEnumerable <Flow_ExternalModel> list)
        {
            try
            {
                using (DBContainer db = new DBContainer())
                {
                    foreach (var model in list)
                    {
                        Flow_External entity = new Flow_External();
                        entity.Id         = ResultHelper.NewId;
                        entity.Title      = model.Title;
                        entity.Remark     = model.Remark;
                        entity.Photo      = model.Photo;
                        entity.SysUserId  = model.SysUserId;
                        entity.TrueName   = model.TrueName;
                        entity.CreateTime = ResultHelper.NowTime;

                        db.Flow_External.Add(entity);
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public virtual Flow_ExternalModel GetById(object id)
        {
            if (IsExists(id))
            {
                Flow_External      entity = m_Rep.GetById(id);
                Flow_ExternalModel model  = new Flow_ExternalModel();
                model.Id         = entity.Id;
                model.Title      = entity.Title;
                model.Remark     = entity.Remark;
                model.Photo      = entity.Photo;
                model.SysUserId  = entity.SysUserId;
                model.TrueName   = entity.TrueName;
                model.CreateTime = entity.CreateTime;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Flow_ExternalModel model)
        {
            ValidationErrors errors = new ValidationErrors();

            try
            {
                Flow_External entity = await m_Rep.GetByIdAsync(model.Id);

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity            = new Flow_External();
                entity.Id         = model.Id;
                entity.Title      = model.Title;
                entity.Remark     = model.Remark;
                entity.Photo      = model.Photo;
                entity.SysUserId  = model.SysUserId;
                entity.TrueName   = model.TrueName;
                entity.CreateTime = model.CreateTime;


                if (await m_Rep.CreateAsync(entity))
                {
                    return(new Tuple <ValidationErrors, bool>(errors, true));
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(new Tuple <ValidationErrors, bool>(errors, false));
            }
        }
        public virtual bool Create(ref ValidationErrors errors, Flow_ExternalModel model)
        {
            try
            {
                Flow_External entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity            = new Flow_External();
                entity.Id         = model.Id;
                entity.Title      = model.Title;
                entity.Remark     = model.Remark;
                entity.Photo      = model.Photo;
                entity.SysUserId  = model.SysUserId;
                entity.TrueName   = model.TrueName;
                entity.CreateTime = model.CreateTime;


                if (m_Rep.Create(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
        public virtual bool Edit(ref ValidationErrors errors, Flow_ExternalModel model)
        {
            try
            {
                Flow_External entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id         = model.Id;
                entity.Title      = model.Title;
                entity.Remark     = model.Remark;
                entity.Photo      = model.Photo;
                entity.SysUserId  = model.SysUserId;
                entity.TrueName   = model.TrueName;
                entity.CreateTime = model.CreateTime;



                if (m_Rep.Edit(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }