Ejemplo n.º 1
0
        // GET: Admin/Default
        public ActionResult Index()
        {
            var _users = userService.FindAll();

            if (_users.Count() > 0)
            {
                return(RedirectToAction("", "", new { Area = "Admin" }));
            }

            var _user = userService.Add(new User {
                UserID = 1, UserName = "******", Email = "*****@*****.**", Password = Encryption.Sha256("admin123"), RealName = "", State = UserState.Super, LoginIP = Request.UserHostAddress, LoginTime = DateTime.Now, RegisterOn = DateTime.Now
            });

            categoryService.Add(new Category {
                CategoryID = 1, Name = "生活", SubTitle = "live", ParentId = 0, CreateTime = DateTime.Now, Type = CategoryType.Article, State = ItemState.Nomal
            });

            commonModelService.Add(new CommonModel {
                Title = "世界,你好", SubTitle = "hello-world", CategoryID = 1, Hits = 0, UserID = 1, Article = new Article {
                    ArticleID = 1, Author = "杨舜杰", Content = "欢迎使用我做的网站,开发语言为C#,数据库是MSSQL", Intro = "欢迎使用我做的网站"
                }, Model = "Article", ReleaseDate = DateTime.Now, State = CommonModelState.UnDelete, Tags = "欢迎,使用"
            });



            return(Success(_user));
        }
Ejemplo n.º 2
0
        public ActionResult Add(CommonModel commonModel, string addtags, string uploadimg)
        {
            if (ModelState.IsValid)
            {
                //设置固定值
                int    userID   = Convert.ToInt32(HttpContext.GetOwinContext().Authentication.User.FindFirst(ClaimTypes.Sid).Value);
                string userName = HttpContext.GetOwinContext().Authentication.User.Identity.Name;
                commonModel.Hits        = 0;
                commonModel.UserID      = userID;
                commonModel.Model       = "Article";
                commonModel.ReleaseDate = System.DateTime.Now;
                commonModel.State       = CommonModelState.Normal;
                if (string.IsNullOrEmpty(commonModel.Article.Author))
                {
                    commonModel.Article.Author = userName;
                }
                commonModel.Model = "Article";
                commonModel       = commonModelService.Add(commonModel);
                tagService.Update(commonModel, add: addtags);

                if (commonModel.ModelID > 0)
                {
                    bool noPic = false;
                    if (string.IsNullOrEmpty(commonModel.DefaultPicUrl))
                    {
                        noPic = true;
                    }

                    if (!string.IsNullOrEmpty(uploadimg))
                    {
                        string[] upload = uploadimg.Split(',');

                        //附件处理
                        AttachmentService _attachmentService = new AttachmentService();
                        //查询相关附件
                        var _attachments = _attachmentService.FindList(0, att => upload.Contains(att.FileParth), OrderType.Desc, att => att.UploadDate).ToList();//_attachmentService.FindList(null, user, string.Empty).ToList();
                        //遍历附件
                        foreach (var _att in _attachments)
                        {
                            var _filePath = Url.Content(_att.FileParth);
                            ////文章首页图片或内容中使用了该附件则更改ModelID为文章保存后的ModelID
                            if ((commonModel.DefaultPicUrl != null && commonModel.DefaultPicUrl.IndexOf(_filePath) >= 0) || commonModel.Article.Content.IndexOf(_filePath) > 0)
                            {
                                if (noPic)
                                {
                                    commonModel.DefaultPicUrl = _filePath;
                                }
                                noPic = false;
                                //var _att = _attachmentService.Find(att => att.FileParth == _filePath);
                                _att.Usage = AttachmentUsage.Aritcle;
                                _att.CommonModels.Add(commonModel);
                                _attachmentService.Update(_att);
                            }
                            //未使用改附件则删除附件和数据库中的记录
                            else if (_att.CommonModels.Count == 0)
                            {
                                System.IO.File.Delete(Server.MapPath(_att.FileParth));
                                _attachmentService.Delete(_att);
                            }
                        }
                    }

                    //string thumbPath = commonModel.DefaultPicUrl.Insert(commonModel.DefaultPicUrl.LastIndexOf('.'), "_s").Replace("image", "thumb");
                    //if (Core.Picture.CreateThumbnail(Server.MapPath(commonModel.DefaultPicUrl), Server.MapPath(thumbPath), 160, 120))
                    //{
                    //    if (!noPic)
                    //    {
                    //        System.IO.File.Delete(Server.MapPath(commonModel.DefaultPicUrl));
                    //        _attachmentService.Delete(_attachments.SingleOrDefault(a => a.FileParth == commonModel.DefaultPicUrl));
                    //    }
                    //    commonModel.DefaultPicUrl = thumbPath;
                    //    commonModelService.Update(commonModel);
                    //}
                    return(Json(true));
                }
            }
            return(View(commonModel));
        }