Beispiel #1
0
        /// <summary>
        /// 添加联系人
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ExcutedResult AddContacts(AddContactsRequest model)
        {
            var user = CurrentUser;

            using (var trans = base.GetNewTransaction())
            {
                Contacts entity = new Contacts
                {
                    Id     = Guid.NewGuid(),
                    UserId = user.Id,
                    Name   = model.Name,
                    Desc   = model.Desc,
                    Mobile = model.Mobile
                };
                Create(entity, out var excuted);
                foreach (var item in model.ContactAccounts)
                {
                    ContactsAccount account = new ContactsAccount
                    {
                        ContactsId = entity.Id,
                        Mobile     = entity.Mobile,
                        Name       = entity.Name,
                        ChainCode  = item.ChainCode,
                        Account    = item.Account,
                        CreateTime = DateTime.UtcNow,
                    };
                    _contactsAccountRepository.Add(account);
                }
                trans.Commit();
            }
            return(ExcutedResult.SuccessResult());
        }
Beispiel #2
0
        /// <summary>
        /// 编辑联系人
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ExcutedResult EditContacts(EditContactsRequest model)
        {
            var entity = GetById(model.Id);

            using (var trans = base.GetNewTransaction())
            {
                entity.Name   = model.Name;
                entity.Mobile = model.Mobile;
                entity.Desc   = model.Desc;
                _contactsAccountRepository.Delete(p => p.ContactsId == entity.Id);
                List <ContactsAccount> accounts = new List <ContactsAccount>();
                foreach (var item in model.ContactAccounts)
                {
                    ContactsAccount account = new ContactsAccount
                    {
                        ContactsId = entity.Id,
                        Mobile     = entity.Mobile,
                        Name       = entity.Name,
                        ChainCode  = item.ChainCode,
                        Account    = item.Account,
                        CreateTime = DateTime.UtcNow,
                    };
                    accounts.Add(account);
                }
                _contactsAccountRepository.AddRange(accounts);
                trans.Commit();
            }
            return(ExcutedResult.SuccessResult());
        }