示例#1
0
        public ActionResult Create([ModelBinder(typeof(MessageModelBinder))]Message model)
        {
            repository.Add(model);

            if (model.ReceiveType == MessageReceiveType.Group)
            {
                model.ReceiveGroup = RepositoryFactory.GetRepository<IDetectionGroupRepository, DetectionGroup>().FindBy(
                    Request.Form["DG"]);
            }
            else if (model.ReceiveType == MessageReceiveType.MultiPerson)
            {
                string[] acocuntIdList = Request.Form["ReceiveAccounts"].Split(',');

                int accountId;
                IAccountRepository accountRepository = RepositoryFactory.GetRepository<IAccountRepository, Account>();

                foreach (string aid in acocuntIdList)
                {
                    if (int.TryParse(aid, out accountId))
                    {
                        Account receiver = accountRepository.FindBy(accountId);
                        if (receiver != null)
                        {
                            MessageAccount ma = new MessageAccount(model, receiver);
                            ma.IsRead = false;

                            repository.SaveMessageAccount(ma);
                            model.MessageAccounts.Add(ma);
                        }
                    }
                }
            }

            #region Attachment

            if (!string.IsNullOrEmpty(Request.Form["AttachmentPath"]))
            {
                IFileShareRepository fsRepository = RepositoryFactory.GetRepository<IFileShareRepository, FileShare>(unitOfWork);
                IFileShareCategoryRepository fsCategoryRepository = RepositoryFactory.GetRepository<IFileShareCategoryRepository, FileShareCategory>(unitOfWork);
                FileShare fs = new FileShare(
                    Guid.NewGuid().ToString("N"),
                    model.Sender,
                    DateTime.Now,
                    true);
                fs.Description = "资讯附件";
                fs.IsPublic = true;
                fs.Name = "资讯 [" + model.Subject + "] - 附件";
                fs.Path = Request.Form["AttachmentPath"];

                IList<FileShareCategory> fsCategories = fsCategoryRepository.FindAll();
                FileShareCategory newsAttachmentCategory = fsCategories.FirstOrDefault(fsc => fsc.Name == "站内信附件");
                if (newsAttachmentCategory == null)
                {
                    newsAttachmentCategory = new FileShareCategory(Guid.NewGuid().ToString("N"), true);
                    newsAttachmentCategory.Name = "站内信附件";

                    fsCategoryRepository.Add(newsAttachmentCategory);
                }
                fs.Category = newsAttachmentCategory;

                fsRepository.Add(fs);
                model.Attachment = fs;
            }

            #endregion

            ReadOnlyCollection<BrokenRule> brokenRules = model.GetBrokenRules();

            if (brokenRules.Count == 0)
            {
                unitOfWork.Commit();

                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = string.Format("成功发送站内信({0})", model.Subject) };
            }
            else
            {
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = "你的输入有误,发送站内信失败" };
                TempData["BrokenRules"] = brokenRules;
                TempData["InvalidModel"] = model;
            }

            return RedirectToAction("Add");
        }
示例#2
0
        public ActionResult Create([ModelBinder(typeof(NewsModelBinder))]News model)
        {
            if (model == null)
            {
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = "操作失败,系统发生了一个错误" };
                return RedirectToAction("Add");
            }

            #region Attachment

            if (!string.IsNullOrEmpty(Request.Form["AttachmentPath"]))
            {
                IFileShareRepository fsRepository = RepositoryFactory.GetRepository<IFileShareRepository, FileShare>(unitOfWork);
                IFileShareCategoryRepository fsCategoryRepository = RepositoryFactory.GetRepository<IFileShareCategoryRepository, FileShareCategory>(unitOfWork);

                FileShare fs = new FileShare(
                    Guid.NewGuid().ToString("N"),
                    model.Publisher,
                    DateTime.Now,
                    true);
                fs.Description = "资讯附件";
                fs.IsPublic = true;
                fs.Name = "资讯 [" + model.Title + "] - 附件";
                fs.Path = Request.Form["AttachmentPath"];

                IList<FileShareCategory> fsCategories = fsCategoryRepository.FindAll();
                FileShareCategory newsAttachmentCategory = fsCategories.FirstOrDefault(fsc => fsc.Name == "资讯附件");
                if (newsAttachmentCategory == null)
                {
                    newsAttachmentCategory = new FileShareCategory(Guid.NewGuid().ToString("N"), true);
                    newsAttachmentCategory.Name = "资讯附件";

                    fsCategoryRepository.Add(newsAttachmentCategory);
                }
                fs.Category = newsAttachmentCategory;

                fsRepository.Add(fs);
                model.Attachment = fs;
            }

            #endregion

            ReadOnlyCollection<BrokenRule> brokenRules = model.GetBrokenRules();

            if (brokenRules.Count == 0)
            {
                repository.Add(model);
                unitOfWork.Commit();

                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = string.Format("成功发布资讯({0})", model.Title) };
            }
            else
            {
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = "你的输入有误,发布资讯失败", Type = Application.HintMessageType.Error };
                TempData["BrokenRules"] = brokenRules;
                TempData["InvalidModel"] = model;
                TempData["AttachmentPath"] = Request.Form["AttachmentPath"];
            }

            return RedirectToAction("Add");
        }
示例#3
0
 public static Boolean CanDelete(FileShareCategory category)
 {
     // TODO: Validate Can Delete
     return !category.IsLocked;
 }
示例#4
0
        public ActionResult Update([ModelBinder(typeof(NewsModelBinder))]News model)
        {
            ReadOnlyCollection<BrokenRule> brokenRules = model.GetBrokenRules();

            #region Attachment

            if (!string.IsNullOrEmpty(Request.Form["AttachmentPath"]))
            {
                IFileShareRepository fsRepository = RepositoryFactory.GetRepository<IFileShareRepository, FileShare>(unitOfWork);
                IFileShareCategoryRepository fsCategoryRepository = RepositoryFactory.GetRepository<IFileShareCategoryRepository, FileShareCategory>(unitOfWork);

                if (model.Attachment == null)
                {
                    FileShare fsNew = new FileShare(
                      Guid.NewGuid().ToString("N"),
                      model.Publisher,
                      DateTime.Now,
                      true);
                    fsNew.Description = "资讯附件";
                    fsNew.IsPublic = true;
                    fsNew.Name = "资讯 [" + model.Title + "] - 附件";
                    fsNew.Path = Request.Form["AttachmentPath"];

                    IList<FileShareCategory> fsCategories = fsCategoryRepository.FindAll();
                    FileShareCategory newsAttachmentCategory = fsCategories.FirstOrDefault(fsc => fsc.Name == "资讯附件");
                    if (newsAttachmentCategory == null)
                    {
                        newsAttachmentCategory = new FileShareCategory(Guid.NewGuid().ToString("N"), true);
                        newsAttachmentCategory.Name = "资讯附件";

                        fsCategoryRepository.Add(newsAttachmentCategory);
                    }
                    fsNew.Category = newsAttachmentCategory;

                    fsRepository.Add(fsNew);
                    model.Attachment = fsNew;
                }
                else
                {
                    if (!model.Attachment.Path.Equals(Request.Form["AttachmentPath"], StringComparison.InvariantCultureIgnoreCase))
                    {
                        FileShare fs = model.Attachment;
                        fsRepository.Remove(fs);

                        FileShare fsNew = new FileShare(Guid.NewGuid().ToString("N"), model.Publisher, DateTime.Now, true);
                        fsNew.Description = "资讯附件";
                        fsNew.IsPublic = true;
                        fsNew.Name = model.Title + " - 附件";
                        fsNew.Path = Request.Form["AttachmentPath"];
                        fsNew.Category = fs.Category;

                        fsRepository.Add(fsNew);
                        model.Attachment = fsNew;
                    }
                }
            }
            else
            {
                if (model.Attachment != null)
                {
                    IFileShareRepository fsRepository = RepositoryFactory.GetRepository<IFileShareRepository, FileShare>(unitOfWork);
                    fsRepository.Remove(model.Attachment);

                    model.Attachment = null;
                }
            }

            #endregion

            if (brokenRules.Count == 0)
            {
                repository[model.Key] = model;
                unitOfWork.Commit();

                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = String.Format("资讯({0})修改成功", model.Title) };
            }
            else
            {
                TempData["InvalidModel"] = model;
                TempData["BrokenRules"] = brokenRules;
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = String.Format("资讯({0})修改失败,请检查你的输入", model.Title) };
            }

            return RedirectToAction("Edit", new { id = model.Key });
        }