예제 #1
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public virtual void SaveImportData(IEnumerable <Spl_ContactCompanyModel> list)
        {
            try
            {
                using (DBContainer db = new DBContainer())
                {
                    foreach (var model in list)
                    {
                        Spl_ContactCompany entity = new Spl_ContactCompany();
                        entity.Id    = ResultHelper.NewId;
                        entity.Code  = model.Code;
                        entity.Name  = model.Name;
                        entity.Phone = model.Phone;
                        entity.ContactCompanyCategoryId = model.ContactCompanyCategoryId;
                        entity.Remark     = model.Remark;
                        entity.Enable     = model.Enable;
                        entity.CreateTime = ResultHelper.NowTime;

                        db.Spl_ContactCompany.Add(entity);
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
예제 #2
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_ContactCompanyModel model)
        {
            ValidationErrors errors = new ValidationErrors();

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

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity       = new Spl_ContactCompany();
                entity.Id    = model.Id;
                entity.Code  = model.Code;
                entity.Name  = model.Name;
                entity.Phone = model.Phone;
                entity.ContactCompanyCategoryId = model.ContactCompanyCategoryId;
                entity.Remark     = model.Remark;
                entity.Enable     = model.Enable;
                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));
            }
        }
예제 #3
0
        public virtual Spl_ContactCompanyModel GetById(object id)
        {
            if (IsExists(id))
            {
                Spl_ContactCompany      entity = m_Rep.GetById(id);
                Spl_ContactCompanyModel model  = new Spl_ContactCompanyModel();
                model.Id    = entity.Id;
                model.Code  = entity.Code;
                model.Name  = entity.Name;
                model.Phone = entity.Phone;
                model.ContactCompanyCategoryId = entity.ContactCompanyCategoryId;
                model.Remark     = entity.Remark;
                model.Enable     = entity.Enable;
                model.CreateTime = entity.CreateTime;

                return(model);
            }
            else
            {
                return(null);
            }
        }
예제 #4
0
        public virtual bool Edit(ref ValidationErrors errors, Spl_ContactCompanyModel model)
        {
            try
            {
                Spl_ContactCompany entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id    = model.Id;
                entity.Code  = model.Code;
                entity.Name  = model.Name;
                entity.Phone = model.Phone;
                entity.ContactCompanyCategoryId = model.ContactCompanyCategoryId;
                entity.Remark     = model.Remark;
                entity.Enable     = model.Enable;
                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);
            }
        }
예제 #5
0
        public virtual bool Create(ref ValidationErrors errors, Spl_ContactCompanyModel model)
        {
            try
            {
                Spl_ContactCompany entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity       = new Spl_ContactCompany();
                entity.Id    = model.Id;
                entity.Code  = model.Code;
                entity.Name  = model.Name;
                entity.Phone = model.Phone;
                entity.ContactCompanyCategoryId = model.ContactCompanyCategoryId;
                entity.Remark     = model.Remark;
                entity.Enable     = model.Enable;
                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);
            }
        }