Beispiel #1
0
        public IActionResult Post([FromBody] PostTopicModel model)
        {
            var postTopic = ModelFactory.Map(model);

            DataService.Add(postTopic);
            return(Ok(ModelFactory.Map(postTopic, Url)));
        }
Beispiel #2
0
        public IActionResult Put(int id, [FromBody] PostTopicModel model)
        {
            var postTopic = ModelFactory.Map(model);

            postTopic.IdPostTopic = id;
            if (!DataService.Update(postTopic))
            {
                return(NotFound());
            }
            return(Ok());
        }
        public ApiResultModel PostTopic(PostTopicModel model)
        {
            ApiResultModel resultModel = new ApiResultModel();

            try
            {
                //根据用户ID查找业主
                IUserBLL userBll = BLLFactory <IUserBLL> .GetBLL("UserBLL");

                T_User user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

                if (user != null)
                {
                    //如果验证Token不通过或已过期
                    if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token)
                    {
                        resultModel.Msg = APIMessage.TOKEN_INVALID;
                        return(resultModel);
                    }

                    //更新最近登录时间和Token失效时间
                    user.LatelyLoginTime  = DateTime.Now;
                    user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));
                    userBll.Update(user);

                    var postTopic = new T_PostBarTopic()
                    {
                        PostUserId      = model.UserId,
                        PostDate        = DateTime.Now,
                        PropertyPlaceId = model.PropertyPlaceId,
                        TopicTypeId     = model.TopicTypeId,
                        Title           = model.Title,
                        Content         = model.Content
                    };

                    //图片上传
                    if (!string.IsNullOrEmpty(model.PicList))
                    {
                        //话题文件资源保存目录
                        string dir = HttpContext.Current.Server.MapPath(ConstantParam.Topic_Pictures_DIR + model.PropertyPlaceId);

                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        var    fileName = DateTime.Now.ToFileTime().ToString() + ".zip";
                        string filepath = Path.Combine(dir, fileName);

                        using (FileStream fs = new FileStream(filepath, FileMode.Create))
                        {
                            using (BinaryWriter bw = new BinaryWriter(fs))
                            {
                                byte[] datas = Convert.FromBase64String(model.PicList);
                                bw.Write(datas);
                                bw.Close();
                            }
                        }
                        //图片集路径保存
                        postTopic.ImgPath = PropertyUtils.UnZip(filepath, dir, ConstantParam.Topic_Pictures_DIR + model.PropertyPlaceId);

                        StringBuilder imgsSB = new StringBuilder();
                        //生成缩略图保存
                        foreach (var path in postTopic.ImgPath.Split(';'))
                        {
                            string thumpFile = DateTime.Now.ToFileTime() + ".jpg";
                            string thumpPath = Path.Combine(HttpContext.Current.Server.MapPath(ConstantParam.Topic_ThumPictures_DIR + model.PropertyPlaceId), thumpFile);
                            PropertyUtils.getThumImage(Path.Combine(HttpContext.Current.Server.MapPath(path)), 18, 3, thumpPath);
                            imgsSB.Append(ConstantParam.Topic_ThumPictures_DIR + model.PropertyPlaceId + "/" + thumpFile + ";");
                        }

                        postTopic.ImgThumbnail = imgsSB.ToString();
                        postTopic.ImgThumbnail = postTopic.ImgThumbnail.Substring(0, postTopic.ImgThumbnail.Length - 1);
                    }

                    //保存话题
                    IPostBarTopicBLL postTopicBLL = BLLFactory <IPostBarTopicBLL> .GetBLL("PostBarTopicBLL");

                    postTopicBLL.Save(postTopic);
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }