Пример #1
0
        private async Task DeleteContact(UserContactType contactType)
        {
            var userContacts = await this.Context.UserContacts
                               .FirstOrDefaultAsync(uc => uc.UserId == this.Update.UserContext.UserId &&
                                                    uc.Type == contactType);

            if (userContacts != null)
            {
                this.Context.UserContacts.Remove(userContacts);
                await this.Context.SaveChangesAsync();
            }
        }
Пример #2
0
        public UserContact EditContactById(Guid id, UserContactType type, string value)
        {
            var contact = GetContactById(id);

            if (contact != null)
            {
                contact.Type  = type;
                contact.Value = value;
                Context.SaveChanges();
                return(contact);
            }
            return(null);
        }
Пример #3
0
        public UserContact AddContactToUser(Guid userId, UserContactType type, string value, DateTime createDate)
        {
            var contact = new UserContact()
            {
                Id         = Guid.NewGuid(),
                UserId     = userId,
                Type       = type,
                Value      = value,
                CreateDate = createDate
            };

            Context.UserContacts.Add(contact);
            Context.SaveChanges();
            return(contact);
        }
Пример #4
0
        public bool AddContact(string currentUserId, User targetUser, UserContactType type)
        {
            targetUser = FindUser(targetUser);
            var contactQuery = from c in _db.Set <UserContact>()
                               where c.UserSourceId == currentUserId && c.UserTargetId == targetUser.Id
                               select c;
            UserContact contact = contactQuery.FirstOrDefault();
            bool        success = false;

            if (contact == null)
            {
                _db.Set <UserContact>().Add(new UserContact()
                {
                    UserContactType = type,
                    UserSourceId    = currentUserId,
                    UserTargetId    = targetUser.Id
                });
                success = true;
            }
            return(success);
        }
Пример #5
0
        public void AddOrUpdateContact(string currentUserId, User targetUser, UserContactType type)
        {
            targetUser = FindUser(targetUser);

            var contactQuery = from c in _db.Set <UserContact>()
                               where c.UserSourceId == currentUserId && c.UserTargetId == targetUser.Id
                               select c;
            UserContact contact = contactQuery.FirstOrDefault();

            if (contact != null)
            {
                contact.UserContactType = type;
            }
            else
            {
                _db.Set <UserContact>().Add(new UserContact()
                {
                    UserContactType = type,
                    UserSourceId    = currentUserId,
                    UserTargetId    = targetUser.Id
                });
            }
            _db.SaveChanges();
        }
Пример #6
0
 public UserContactDTO(User user, UserContactType type)
 {
     User = user;
     Type = type;
 }
Пример #7
0
 public UserContact(UserContactType type, string value)
 {
     Type  = type;
     Value = value;
 }