Example #1
0
        public OrganizationDTO CreateOrganization(NewOrganizationDTO organization)
        {
            using (var context = new ApplicationDbContext())
            {
                if (!User.IsInRole("Admin"))
                {
                    throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden);
                }
                var password = GeneratePasswordHash(organization.Password);
                var address  = new Address()
                {
                    StreetAddressOne = organization.StreetAddressOne,
                    StreetAddressTwo = organization.StreetAddressTwo,
                    City             = organization.City,
                    State            = organization.State,
                    ZipCode          = organization.ZipCode
                };

                var tags = context.Tags.Where(t => organization.Tags.Any(ot => ot.Id == t.ID)).ToList();

                var orgEntity = new ApplicationUser()
                {
                    Address            = address,
                    Category           = organization.OrganizationCategory,
                    DisplayName        = organization.DisplayName,
                    Email              = organization.Email,
                    FirstName          = organization.FirstName,
                    LastName           = organization.LastName,
                    PasswordHash       = password,
                    PhoneNumber        = organization.PhoneNumber,
                    ProfileDescription = organization.ProfileDescription,
                    UserName           = organization.Email,
                    Tags = tags
                };

                context.Users.Add(orgEntity);
                context.SaveChanges();

                return(new OrganizationDTO()
                {
                    City = organization.City,
                    DisplayName = organization.DisplayName,
                    Email = organization.Email,
                    FirstName = organization.FirstName,
                    LastName = organization.LastName,
                    OrganizationCategory = organization.OrganizationCategory,
                    PhoneNumber = organization.PhoneNumber,
                    ProfileDescription = organization.ProfileDescription,
                    State = organization.State,
                    StreetAddressOne = organization.StreetAddressOne,
                    StreetAddressTwo = organization.StreetAddressTwo,
                    ZipCode = organization.ZipCode,
                    Tags = organization.Tags
                });
            }
        }
Example #2
0
        //private void Recursion(List<Organization> lstOrg, OrganizationDTO currentItem)
        //{
        //    var lstChilds = Mapper.Map<List<OrganizationDTO>>(lstOrg.Where(p => p.ParentId == currentItem.Id).ToList());
        //    currentItem.lstChilds = lstChilds;
        //    foreach (var item in lstChilds)
        //    {
        //        Recursion(lstOrg, item);
        //    }
        //}
        private void NewRecursion(List <Organization> lstOrg, NewOrganizationDTO currentItem)
        {
            var items = Mapper.Map <List <NewOrganizationDTO> >(lstOrg.Where(p => p.ParentId == currentItem.Id).OrderByDescending(o => o.CreateDate).ToList());

            currentItem.items = items;
            foreach (var item in items)
            {
                NewRecursion(lstOrg, item);
            }
        }