public ActionResult Create(GroupEditModel groupEditModel)
        {
            string errorMessage = null;
            if (ModelState.HasBannedWord(out errorMessage))
            {
                return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = errorMessage,
                    Title = "创建失败",
                    StatusMessageType = StatusMessageType.Hint
                }));
            }

            System.IO.Stream stream = null;
            HttpPostedFileBase groupLogo = Request.Files["GroupLogo"];

            //已修改
            IUser user = UserContext.CurrentUser;
            if (user == null)
                return Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!"));

            if (!authorizer.Group_Create(out errorMessage))
            {
                return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = errorMessage,
                    Title = errorMessage,
                    StatusMessageType = StatusMessageType.Hint
                }));
            }
            if (groupLogo != null && !string.IsNullOrEmpty(groupLogo.FileName))
            {
                TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Group());
                if (!tenantLogoSettings.ValidateFileLength(groupLogo.ContentLength))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024)));
                    return View(groupEditModel);
                }

                LogoSettings logoSettings = DIContainer.Resolve<ISettingsManager<LogoSettings>>().Get();
                if (!logoSettings.ValidateFileExtensions(groupLogo.FileName))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions);
                    return View(groupEditModel);
                }
                stream = groupLogo.InputStream;
                groupEditModel.Logo = groupLogo.FileName;
            }
            GroupEntity group = groupEditModel.AsGroupEntity();

            bool result = groupService.Create(user.UserId, group);

            if (stream != null)
            {
                groupService.UploadLogo(group.GroupId, stream);
            }
            //设置分类
            if (groupEditModel.CategoryId > 0)
            {
                categoryService.AddItemsToCategory(new List<long>() { group.GroupId }, groupEditModel.CategoryId);
            }
            //设置标签
            string relatedTags = Request.Form.Get<string>("RelatedTags");
            if (!string.IsNullOrEmpty(relatedTags))
            {
                tagService.AddTagsToItem(relatedTags, group.GroupId, group.GroupId);
            }
            //发送邀请
            if (!string.IsNullOrEmpty(groupEditModel.RelatedUserIds))
            {

                //已修改
                IEnumerable<long> userIds = Request.Form.Gets<long>("RelatedUserIds", null);
                groupService.SendInvitations(group, user, string.Empty, userIds);
            }
            return Redirect(SiteUrls.Instance().GroupHome(group.GroupKey));
        }
示例#2
0
        public ActionResult EditGroup(string spaceKey, GroupEditModel groupEditModel)
        {
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!")));
            }
            System.IO.Stream   stream    = null;
            HttpPostedFileBase groupLogo = Request.Files["GroupLogo"];

            if (groupLogo != null && !string.IsNullOrEmpty(groupLogo.FileName))
            {
                TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Group());
                if (!tenantLogoSettings.ValidateFileLength(groupLogo.ContentLength))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024)));
                    return(View(groupEditModel));
                }

                LogoSettings logoSettings = DIContainer.Resolve <ILogoSettingsManager>().Get();
                if (!logoSettings.ValidateFileExtensions(groupLogo.FileName))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions);
                    return(View(groupEditModel));
                }
                stream = groupLogo.InputStream;
                groupEditModel.Logo = groupLogo.FileName;
            }

            GroupEntity group = groupEditModel.AsGroupEntity();


            //设置分类
            if (groupEditModel.CategoryId > 0)
            {
                categoryService.ClearCategoriesFromItem(group.GroupId, 0, TenantTypeIds.Instance().Group());
                categoryService.AddItemsToCategory(new List <long>()
                {
                    group.GroupId
                }, groupEditModel.CategoryId, 0);
            }


            //已修改
            //设置标签
            string relatedTags = Request.Form.Get <string>("RelatedTags");

            if (!string.IsNullOrEmpty(relatedTags))
            {
                tagService.ClearTagsFromItem(group.GroupId, group.GroupId);
                tagService.AddTagsToItem(relatedTags, group.GroupId, group.GroupId);
            }
            if (stream != null)
            {
                groupService.UploadLogo(group.GroupId, stream);
            }

            groupService.Update(currentUser.UserId, group);
            TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功!");
            return(Redirect(SiteUrls.Instance().EditGroup(group.GroupKey)));
        }
示例#3
0
        public ActionResult Create(GroupEditModel groupEditModel)
        {
            string errorMessage = null;

            if (ModelState.HasBannedWord(out errorMessage))
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = errorMessage,
                    Title = "创建失败",
                    StatusMessageType = StatusMessageType.Error
                })));
            }

            System.IO.Stream   stream    = null;
            HttpPostedFileBase groupLogo = Request.Files["GroupLogo"];


            //已修改
            IUser user = UserContext.CurrentUser;

            if (user == null)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!")));
            }

            if (!new Authorizer().Group_Create(out errorMessage))
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Body = errorMessage,
                    Title = errorMessage,
                    StatusMessageType = StatusMessageType.Error
                })));
            }
            if (groupLogo != null && !string.IsNullOrEmpty(groupLogo.FileName))
            {
                TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Group());
                if (!tenantLogoSettings.ValidateFileLength(groupLogo.ContentLength))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024)));
                    return(View(groupEditModel));
                }

                LogoSettings logoSettings = DIContainer.Resolve <ILogoSettingsManager>().Get();
                if (!logoSettings.ValidateFileExtensions(groupLogo.FileName))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions);
                    return(View(groupEditModel));
                }
                stream = groupLogo.InputStream;
                groupEditModel.Logo = groupLogo.FileName;
            }
            GroupEntity group = groupEditModel.AsGroupEntity();

            bool result = groupService.Create(user.UserId, group);

            if (stream != null)
            {
                groupService.UploadLogo(group.GroupId, stream);
            }
            //设置分类
            if (groupEditModel.CategoryId > 0)
            {
                categoryService.AddItemsToCategory(new List <long>()
                {
                    group.GroupId
                }, groupEditModel.CategoryId, 0);
            }
            //设置标签
            string relatedTags = Request.Form.Get <string>("RelatedTags");

            if (!string.IsNullOrEmpty(relatedTags))
            {
                tagService.AddTagsToItem(relatedTags, group.GroupId, group.GroupId);
            }
            //发送邀请
            if (!string.IsNullOrEmpty(groupEditModel.RelatedUserIds))
            {
                //已修改
                IEnumerable <long> userIds = Request.Form.Gets <long>("RelatedUserIds", null);
                groupService.SendInvitations(group, user, string.Empty, userIds);
            }
            return(Redirect(SiteUrls.Instance().GroupHome(group.GroupKey)));
        }
        public ActionResult EditGroup(string spaceKey, GroupEditModel groupEditModel)
        {
            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
                return Json(new StatusMessageData(StatusMessageType.Error, "您尚未登录!"));
            System.IO.Stream stream = null;
            HttpPostedFileBase groupLogo = Request.Files["GroupLogo"];

            if (groupLogo != null && !string.IsNullOrEmpty(groupLogo.FileName))
            {
                TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Group());
                if (!tenantLogoSettings.ValidateFileLength(groupLogo.ContentLength))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024)));
                    return View(groupEditModel);
                }

                LogoSettings logoSettings = DIContainer.Resolve<ISettingsManager<LogoSettings>>().Get();
                if (!logoSettings.ValidateFileExtensions(groupLogo.FileName))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions);
                    return View(groupEditModel);
                }
                stream = groupLogo.InputStream;
                groupEditModel.Logo = groupLogo.FileName;
            }

            GroupEntity group = groupEditModel.AsGroupEntity();

            //设置分类
            if (groupEditModel.CategoryId > 0)
            {
                categoryService.ClearCategoriesFromItem(group.GroupId, 0, TenantTypeIds.Instance().Group());
                categoryService.AddItemsToCategory(new List<long>() { group.GroupId }, groupEditModel.CategoryId);
            }

            //已修改
            //设置标签
            string relatedTags = Request.Form.Get<string>("RelatedTags");
            if (!string.IsNullOrEmpty(relatedTags))
            {
                tagService.ClearTagsFromItem(group.GroupId, group.GroupId);
                tagService.AddTagsToItem(relatedTags, group.GroupId, group.GroupId);
            }
            if (stream != null)
            {
                groupService.UploadLogo(group.GroupId, stream);
            }

            groupService.Update(currentUser.UserId, group);
            TempData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Success, "更新成功!");
            return Redirect(SiteUrls.Instance().EditGroup(group.GroupKey));
        }