public virtual bool Create(ref ValidationErrors errors, MIS_WebIM_RecentContactModel model)
        {
            try
            {
                MIS_WebIM_RecentContact entity = m_Rep.GetById(model.Id);
                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(false);
                }
                entity                     = new MIS_WebIM_RecentContact();
                entity.Id                  = model.Id;
                entity.ContactPersons      = model.ContactPersons;
                entity.UserId              = model.UserId;
                entity.InfoTime            = model.InfoTime;
                entity.ContactPersonsTitle = model.ContactPersonsTitle;


                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);
            }
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        public virtual void SaveImportData(IEnumerable <MIS_WebIM_RecentContactModel> list)
        {
            try
            {
                using (DBContainer db = new DBContainer())
                {
                    foreach (var model in list)
                    {
                        MIS_WebIM_RecentContact entity = new MIS_WebIM_RecentContact();
                        entity.Id                  = 0;
                        entity.ContactPersons      = model.ContactPersons;
                        entity.UserId              = model.UserId;
                        entity.InfoTime            = model.InfoTime;
                        entity.ContactPersonsTitle = model.ContactPersonsTitle;

                        db.MIS_WebIM_RecentContact.Add(entity);
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public virtual bool Edit(ref ValidationErrors errors, MIS_WebIM_RecentContactModel model)
        {
            try
            {
                MIS_WebIM_RecentContact entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id                  = model.Id;
                entity.ContactPersons      = model.ContactPersons;
                entity.UserId              = model.UserId;
                entity.InfoTime            = model.InfoTime;
                entity.ContactPersonsTitle = model.ContactPersonsTitle;



                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);
            }
        }
        public virtual MIS_WebIM_RecentContactModel GetById(object id)
        {
            if (IsExists(id))
            {
                MIS_WebIM_RecentContact      entity = m_Rep.GetById(id);
                MIS_WebIM_RecentContactModel model  = new MIS_WebIM_RecentContactModel();
                model.Id                  = entity.Id;
                model.ContactPersons      = entity.ContactPersons;
                model.UserId              = entity.UserId;
                model.InfoTime            = entity.InfoTime;
                model.ContactPersonsTitle = entity.ContactPersonsTitle;

                return(model);
            }
            else
            {
                return(null);
            }
        }
Пример #5
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(MIS_WebIM_RecentContactModel model)
        {
            ValidationErrors errors = new ValidationErrors();

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

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity                     = new MIS_WebIM_RecentContact();
                entity.Id                  = model.Id;
                entity.ContactPersons      = model.ContactPersons;
                entity.UserId              = model.UserId;
                entity.InfoTime            = model.InfoTime;
                entity.ContactPersonsTitle = model.ContactPersonsTitle;


                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));
            }
        }