예제 #1
0
        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;
        }
예제 #2
0
        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;
            }
        }