public async Task<JsonResult> Edit(CommunityInputViewModel community)
        {
            if (CurrentUserId == 0)
            {
                await TryAuthenticateFromHttpContext(_communityService, _notificationService);
            }
            try
            {
                var communityDetails = new CommunityDetails();
                Mapper.Map(community, communityDetails);

                // Set thumbnail properties
                communityDetails.Thumbnail = new FileDetail {AzureID = community.ThumbnailID};

                if (CurrentUserId == 0)
                {
                    return Json("error: user not logged in");
                }
                _communityService.UpdateCommunity(communityDetails, CurrentUserId);
                return Json(new {id = community.ID});
            }
            catch (Exception exception)
            {
                
            }

            return Json("error: community not saved");
            
        }
        public async Task<JsonResult> CommunityDetail(long? id, bool? edit)
        {
            if (CurrentUserId == 0)
            {
                await TryAuthenticateFromHttpContext(_communityService, _notificationService);
            }
            var communityDetails = await _communityService.GetCommunityDetails(id.Value, CurrentUserId, true, true);
            var permissionDetails = GetUserPermissionDetails(id.Value, PermissionsTab.Users, 0);
            
            if (edit == true)
            {
                var communityInputViewModel = new CommunityInputViewModel();
                Mapper.Map(communityDetails, communityInputViewModel);
                var json = new
                {
                    community = communityInputViewModel, 
                    permission = permissionDetails
                };
                return Json(json, JsonRequestBehavior.AllowGet);
            }
            var communityViewModel = new CommunityViewModel();
            Mapper.Map(communityDetails, communityViewModel);
            
            if (communityViewModel.AccessType != AccessType.Private || communityViewModel.UserPermission >= Permission.Reader)
            {
                var json = new
                {
                    community = communityViewModel, 
                    permission = permissionDetails
                };
                return Json(json,JsonRequestBehavior.AllowGet);
            }

            return new JsonResult
            {
                Data = new { communityViewModel.Name, communityViewModel.Id, error = "insufficient permission" },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
            
        }
        public async Task<ActionResult> New(CommunityInputViewModel communityJson)
        {
            if (CurrentUserId == 0)
            {
                await TryAuthenticateFromHttpContext(_communityService, _notificationService);
            }

            if (ModelState.IsValid)
            {
                var communityDetails = new CommunityDetails();
                Mapper.Map(communityJson, communityDetails);

                // Set thumbnail properties
                communityDetails.Thumbnail = new FileDetail() { AzureID = communityJson.ThumbnailID };
                communityDetails.CreatedByID = CurrentUserId;
                communityJson.ID = communityDetails.ID = _communityService.CreateCommunity(communityDetails);

                // Send Notification Mail
                _notificationService.NotifyNewEntityRequest(communityDetails, HttpContext.Request.Url.GetServerLink());

                return new JsonResult { Data = new { ID = communityDetails.ID } };
            }
            
            // In case of any validation error stay in the same page.
            return new JsonResult { Data = false };
        }