public Group CreateGroup(UserInformationModel<User> aUser, EditGroupModel aGroupModel)
        {
            if (!ValidGroup(aGroupModel, true)
                | !ValidTags(aGroupModel.KeywordTags, aGroupModel.ZipCodeTags, aGroupModel.CityTag, aGroupModel.StateTag)) {
                return null;
            }

            Group myGroup = theGroupRepository.CreateGroup(aUser.Details, aGroupModel.Name,
                aGroupModel.Description, aGroupModel.AutoAccept, aGroupModel.MakePublic);

            try {
                int myIntHolder;
                List<int> myZipCodes = aGroupModel.ZipCodeTags.Split(',').Where(z => int.TryParse(z.Trim(), out myIntHolder)).Select(z => int.Parse(z)).ToList(); ;
                List<string> myKeyWords = aGroupModel.KeywordTags.Split(',').Select(k => k.Trim()).Where(k => !string.IsNullOrEmpty(k)).ToList();
                theGroupRepository.AddTagsForGroup(aUser.Details, myGroup.Id, myZipCodes, myKeyWords, aGroupModel.CityTag, aGroupModel.StateTag);
                theGroupRepository.AddMemberToGroup(aUser.Details, aUser.Details.Id, myGroup.Id, aGroupModel.CreatorTitle, true);
            } catch (Exception myException) {
                theGroupRepository.RefreshConnection();
                theGroupRepository.DeleteGroup(myGroup.Id);
                throw new Exception("Error adding the creating member of the group as a group member. So we deleted the group.", myException);
            }

            return myGroup;
        }
        private bool ValidGroup(EditGroupModel aGroupModel, bool aIsCreating)
        {
            if (aIsCreating) {
                ValidTitle(aGroupModel.CreatorTitle);
            }

            if (string.IsNullOrEmpty(aGroupModel.Name)) {
                theValidationDictionary.AddError("Name", aGroupModel.Name, "A group name is required.");
            } else if (!VarCharValidation.Valid50Length(aGroupModel.Name)) {
                theValidationDictionary.AddError("Name", aGroupModel.Name, "Your group name is too long.");
            }

            if (string.IsNullOrEmpty(aGroupModel.Description)) {
                theValidationDictionary.AddError("Description", aGroupModel.Description, "Some description is required.");
            }

            return theValidationDictionary.isValid;
        }
        public EditGroupModel GetGroupForEdit(UserInformationModel<User> aUser, int aGroupId)
        {
            if (!IsAdmin(aUser, aGroupId)) {
                if (!PermissionHelper<User>.AllowedToPerformAction(theValidationDictionary, aUser, SocialPermission.Edit_Any_Group)) {
                    throw new PermissionDenied(ErrorKeys.PERMISSION_DENIED);
                }
            }

            Group myGroup = theGroupRepository.GetGroup(aUser.Details, aGroupId);
            EditGroupModel myEditGroup = new EditGroupModel(myGroup) {
                ViewAction = ViewAction.Edit
            };
            return myEditGroup;
        }
        public bool EditGroup(UserInformationModel<User> aUserEditing, EditGroupModel anEditGroupModel)
        {
            if (!ValidGroup(anEditGroupModel, false)
                | !ValidTags(anEditGroupModel.KeywordTags, anEditGroupModel.ZipCodeTags, anEditGroupModel.CityTag, anEditGroupModel.StateTag)) {
                return false;
            }

            Group myGroup = theGroupRepository.GetGroup(aUserEditing.Details, anEditGroupModel.Id);
            IEnumerable<int> myCurrentZipCodes = myGroup.GroupZipCodeTags.Select(z => z.ZipCode);
            IEnumerable<string> myCurrentTags = myGroup.GroupTags.Select(t => t.Tag);

            myGroup.Name = anEditGroupModel.Name;
            myGroup.Description = anEditGroupModel.Description;
            myGroup.AutoAccept = anEditGroupModel.AutoAccept;
            myGroup.MakePublic = anEditGroupModel.MakePublic;
            myGroup.LastEditedByUserId = aUserEditing.UserId;
            myGroup.LastEditedDateTimeStamp = DateTime.UtcNow;

            theGroupRepository.UpdateGroup(myGroup);

            int myIntHolder;
            List<int> myEditedZipCodes = anEditGroupModel.ZipCodeTags.Split(',').Where(z => int.TryParse(z.Trim(), out myIntHolder)).Select(z => int.Parse(z)).ToList<int>();
            List<string> myEditedKeyWords = anEditGroupModel.KeywordTags.Split(',').Select(k => k.Trim()).Where(k => !string.IsNullOrEmpty(k)).ToList<string>();

            IEnumerable<int> myZipCodesToAdd = myEditedZipCodes.Except(myCurrentZipCodes);
            IEnumerable<string> myKeywordsToAdd = myEditedKeyWords.Except(myCurrentTags);

            List<int> myZipCodesToDelete = myCurrentZipCodes.Except(myEditedZipCodes).ToList<int>();
            List<string> myKeywordsToDelete = myCurrentTags.Except(myEditedKeyWords).ToList<string>();

            bool myDeleteCityStateTag = false;

            if (string.IsNullOrEmpty(anEditGroupModel.CityTag) || anEditGroupModel.StateTag.Equals(Constants.SELECT)) {
                myDeleteCityStateTag = true;
            }

            bool myAddNewCityStateTag = false;
            GroupCityStateTag myCityStateTag = theGroupRepository.GetGroupCityStateTag(anEditGroupModel.Id);

            if ((myCityStateTag == null && !string.IsNullOrEmpty(anEditGroupModel.CityTag) && !string.IsNullOrEmpty(anEditGroupModel.StateTag) && !anEditGroupModel.StateTag.Equals(Constants.SELECT))
                || (myCityStateTag != null && (!anEditGroupModel.CityTag.Equals(myCityStateTag.City) || !anEditGroupModel.StateTag.Equals(myCityStateTag.State)))) {
                myDeleteCityStateTag = true;
                myAddNewCityStateTag = true;
            }

            theGroupRepository.UpdateTagsForGroup(aUserEditing.Details, anEditGroupModel.Id,
                                                  myZipCodesToAdd, myZipCodesToDelete, myKeywordsToAdd,
                                                  myKeywordsToDelete, myDeleteCityStateTag, myAddNewCityStateTag,
                                                  anEditGroupModel.CityTag, anEditGroupModel.StateTag);

            return true;
        }
        public ActionResult Create(EditGroupModel aGroupModel)
        {
            if (!IsLoggedIn()) {
                return RedirectToLogin();
            }

            UserInformationModel<User> myUserInformation = GetUserInformatonModel();

            try {
                Group myGroup = theGroupService.CreateGroup(myUserInformation, aGroupModel);

                if (myGroup != null) {
                    TempData["Message"] += MessageHelper.SuccessMessage(GROUP_CREATED);
                    return RedirectToAction("Details", new { id = myGroup.Id });
                }
            } catch (Exception myException) {
                LogError(myException, ErrorKeys.ERROR_MESSAGE);
                TempData["Message"] = MessageHelper.ErrorMessage(ErrorKeys.ERROR_MESSAGE);
                theValidationDictionary.ForceModleStateExport();
            }

            return RedirectToAction("Create");
        }
        public ActionResult Edit(EditGroupModel anEditGroupModel)
        {
            if (!IsLoggedIn()) {
                return RedirectToLogin();
            }

            UserInformationModel<User> myUserInformation = GetUserInformatonModel();

            try {
                bool myResult = theGroupService.EditGroup(myUserInformation, anEditGroupModel);

                if (myResult) {
                    TempData["Message"] += MessageHelper.SuccessMessage(GROUP_EDITED);
                    return RedirectToAction("Details", new { id = anEditGroupModel.Id });
                }
            } catch (Exception myException) {
                LogError(myException, ErrorKeys.ERROR_MESSAGE);
                TempData["Message"] += MessageHelper.ErrorMessage(ErrorKeys.ERROR_MESSAGE);
                theValidationDictionary.ForceModleStateExport();
            }

            return RedirectToAction("Edit", new { id = anEditGroupModel.Id });
        }