public bool AddContactGroup(string userName, ContactGroup entity)
        {
            try
            {
                var user = _contex.Users.SingleOrDefault(c => c.Id == entity.UserId);
                entity.CreatedBy = user;
                entity.DateCreated = DateTime.Now;
                entity.DateLastModified = DateTime.Now;

                if (entity.GroupRefId != null)
                {
                    var parentGroup = _contex.ContactGroups.SingleOrDefault(c => c.Id == entity.GroupRefId);
                    entity.ParentGroup = parentGroup;
                }

                entity.GroupRefId = null;

                _contex.ContactGroups.Add(entity);

                _contex.SaveChanges();

                return true;

            }
            catch (Exception)
            {
                return false;
            }
        }
        public ContactGroup Parse(ContactGroupModel model,string username)
        {
            try
            {
                var contactGroup = new ContactGroup();

                contactGroup.Name = model.GroupName;
                contactGroup.FirstResponder = model.FirstResponder;

                return contactGroup;
            }
            catch (Exception)
            {
                return null;
            }
        }
        public ContactGroupModel Create(ContactGroup contactGroup, bool includeContacts)
        {
            var result = new ContactGroupModel()
            {
                URL = _urlHelper.Link("ContactGroup", new { id = contactGroup.CreatedBy.Id, contactgroupid = contactGroup.Id }),
                Id = contactGroup.Id,
                Name = contactGroup.Name,
                DateCreated = contactGroup.DateCreated,
                ChildGroups = contactGroup.ChildGroups.Select(c => Create(c,false)),
                ParentGroupName =  contactGroup.ParentGroup != null ? contactGroup.ParentGroup.Name : "",
                ParentGroupURL = contactGroup.ParentGroup != null ? _urlHelper.Link("ContactGroup", new { id = contactGroup.ParentGroup.CreatedBy.Id, contactGroup = contactGroup.ParentGroup.Id }) : "",
            };

            if (includeContacts)
                result.Contacts = contactGroup.Contacts.Select(c => Create(c));

            return result;
        }
Beispiel #4
0
        public ContactGroupModel Create(ContactGroup contactGroup, bool includeContacts = false)
        {
            var result = new ContactGroupModel()
            {
                Id = contactGroup.Id,
                GroupName = contactGroup.Name,
                FirstResponder = contactGroup.FirstResponder != null ? Convert.ToBoolean(contactGroup.FirstResponder) : false,
                ContactsCount = contactGroup.Contacts.Count,
                LastModified = contactGroup.DateLastModified,
                CreatedBy = contactGroup.CreatedBy.UserID,
                ChildGroups = contactGroup.ChildGroups.Select(c => Create(c)),
            };

            if (includeContacts)
                result.Contacts = contactGroup.Contacts.Select(c => Create(c));

            return result;
        }
        public ContactGroup Parse(ContactGroupModel model)
        {
            try
            {
                var user = new ContactGroup();

                user.Name = model.Name;

                if (model.ParentGroupId != 0 && model.ParentGroupId == null)
                {
                    user.GroupRefId = model.ParentGroupId;
                }
                else
                {
                    user.GroupRefId = model.ChildGroupId;
                }

                ////Below code is an example of how to get ID for url's pass in to the model
                //var uri = new Uri(model.URL);
                //var notificationId = int.Parse(uri.Segments.Last());

                return user;
            }
            catch (Exception)
            {
                return null;
            }
        }
 public ContactGroupModel Create(ContactGroup contactGroup)
 {
     throw new NotImplementedException();
 }
        public bool EditContactGroup(int contactGroupId,ContactGroup entity)
        {
            try
            {
                var contactGroup = _contex.ContactGroups.SingleOrDefault(c => c.Id == contactGroupId);

                if (contactGroup != null)
                {
                    contactGroup.Name = entity.Name;
                    contactGroup.FirstResponder = entity.FirstResponder;
                    contactGroup.DateLastModified = DateTime.Now;

                    if(SaveAll())
                        return true;
                }

                    return false;

            }
            catch (Exception)
            {
                return false;

            }
        }