Пример #1
0
        public AddResultBaseModel <int> Add(AddContactModel model)
        {
            string cName = model.Cname;
            string eName = string.Empty;

            if (model.Cname.Contains("/"))
            {
                eName = model.Cname;
                cName = string.Empty;
            }
            List <ContactInfoEntity> contactInfoEntities = _contactDal.Query <ContactInfoEntity>(
                n => n.Cid == model.Cid && n.IsDel == "F" && (n.Cname == model.Cname || n.Ename == model.Cname), true)
                                                           .ToList();

            if (contactInfoEntities != null && contactInfoEntities.Count > 0)
            {
                List <int> contactId = new List <int>();
                contactInfoEntities.ForEach(n => contactId.Add(n.Contactid));
                int count = _contactIdentificationDal.Query <ContactIdentificationInfoEntity>(
                    n => contactId.Contains(n.Contactid) && n.CardNo == model.CardNo, true).Count();
                if (count > 0)
                {
                    throw new Exception("当前已经存在该信息");
                }
            }


            ContactInfoEntity contactInfo = new ContactInfoEntity()
            {
                Cname          = cName,
                Ename          = eName,
                Mobile         = model.Mobile,
                Cid            = model.Cid,
                LastUpdateTime = DateTime.Now,
                IsDel          = "F",
                IsPassenger    = model.IsPassenger,
                UpdateOid      = "sys",
                DelTime        = DateTime.Now,
                Email          = model.Email,
                IsOnline       = (model.OrderSource == "O" ? 0 : 1)
            };

            contactInfo = _contactDal.Insert <ContactInfoEntity>(contactInfo);

            _contactIdentificationDal.Insert <ContactIdentificationInfoEntity>(new ContactIdentificationInfoEntity()
            {
                Contactid      = contactInfo.Contactid,
                CardNo         = model.CardNo,
                Iid            = model.Iid,
                LastUpdateTime = DateTime.Now
            });

            return(new AddResultBaseModel <int>()
            {
                IsSuccessed = true,
                Id = contactInfo.Contactid
            });
        }
Пример #2
0
        public AddResultBaseModel <int> Edit(EditContactModel model)
        {
            ContactInfoEntity contactInfoEntity = _contactDal.Find <ContactInfoEntity>(model.ContactId);

            if (model.Cname.Contains("/"))
            {
                contactInfoEntity.Ename = model.Cname;
                contactInfoEntity.Cname = string.Empty;
            }
            else
            {
                contactInfoEntity.Cname = model.Cname;
                contactInfoEntity.Ename = string.Empty;
            }

            contactInfoEntity.Mobile         = model.Mobile;
            contactInfoEntity.LastUpdateTime = DateTime.Now;
            contactInfoEntity.UpdateOid      = "sys";
            contactInfoEntity.DelTime        = DateTime.Now;
            contactInfoEntity.Email          = model.Email;
            if (!string.IsNullOrEmpty(model.IsDel))
            {
                contactInfoEntity.IsDel = model.IsDel;
            }

            _contactDal.Update(contactInfoEntity);

            ContactIdentificationInfoEntity contactIdentificationInfoEntity =
                _contactIdentificationDal.Query <ContactIdentificationInfoEntity>(
                    n => n.Contactid == model.ContactId && n.Iid == model.Iid, true).FirstOrDefault();

            if (contactIdentificationInfoEntity != null)
            {
                contactIdentificationInfoEntity.Iid            = model.Iid;
                contactIdentificationInfoEntity.CardNo         = model.CardNo;
                contactIdentificationInfoEntity.LastUpdateTime = DateTime.Now;
                _contactIdentificationDal.Update(contactIdentificationInfoEntity);
            }
            else
            {
                _contactIdentificationDal.Insert <ContactIdentificationInfoEntity>(new ContactIdentificationInfoEntity()
                {
                    Contactid      = model.ContactId,
                    CardNo         = model.CardNo,
                    Iid            = model.Iid,
                    LastUpdateTime = DateTime.Now
                });
            }

            return(new AddResultBaseModel <int>()
            {
                IsSuccessed = true, Id = model.ContactId
            });
        }
        public bool PostIdentification(IdentificationModel model, int cid)
        {
            var contact = _contactDal.Query <ContactInfoEntity>(a => a.PCid == cid).FirstOrDefault();

            if (contact == null)
            {
                throw new Exception("当前客户信息异常,不能修改");
            }

            if (model.IsDefault == 1)
            {
                contact.DefaultIdentificationId = model.Iid;
                _contactDal.Update <ContactInfoEntity>(contact, new string[] { "DefaultIdentificationId" });
            }
            else
            {
                if (contact.DefaultIdentificationId.HasValue && contact.DefaultIdentificationId.Value == model.Iid)
                {
                    contact.DefaultIdentificationId = 0;
                    _contactDal.Update <ContactInfoEntity>(contact, new string[] { "DefaultIdentificationId" });
                }
            }

            model.ContactId = contact.Contactid;
            //判断当前公司下,是否存在相同证件,如果存在,则不许修改
            CustomerModel customerModel = _getCustomerBll.GetCustomerByCid(cid);

            if (!string.IsNullOrEmpty(customerModel.CorpID))
            {
                List <CustomerModel> customerModels = _getCustomerBll.GetCustomerByCorpId(customerModel.CorpID);
                List <int>           cidList        = new List <int>();
                customerModels.ForEach(n =>
                {
                    if (n.Cid != cid)
                    {
                        cidList.Add(n.Cid);
                    }
                });

                List <ContactInfoEntity> contactInfoEntities =
                    _contactDal.Query <ContactInfoEntity>(a => cidList.Contains(a.PCid ?? 0)).ToList();

                List <int> contactIdList = new List <int>();

                contactInfoEntities.ForEach(n => contactIdList.Add(n.Contactid));

                List <ContactIdentificationInfoEntity> infoList =
                    _contactIdentificationDal.Query <ContactIdentificationInfoEntity>(
                        n =>
                        contactIdList.Contains(n.Contactid) && !string.IsNullOrEmpty(n.CardNo) &&
                        n.CardNo.ToUpper() == model.CardNo.ToUpper() && n.Iid == model.Iid)
                    .ToList();

                if (infoList != null && infoList.Count > 0)
                {
                    throw new Exception("当前公司存在相同证件号,不能修改");
                }
            }


            var identifications = _contactIdentificationDal.Query <ContactIdentificationInfoEntity>(a => a.Contactid == model.ContactId && a.Iid == model.Iid);
            var entity          = Mapper.Map <IdentificationModel, ContactIdentificationInfoEntity>(model);

            entity.LastUpdateTime = DateTime.Now;
            entity.CardNo         = entity.CardNo ?? "";
            if (identifications != null && identifications.Any())
            {
                _contactIdentificationDal.Update <ContactIdentificationInfoEntity>(entity);
            }
            else
            {
                _contactIdentificationDal.Insert <ContactIdentificationInfoEntity>(entity);
            }
            return(true);
        }