示例#1
0
        public async Task <IActionResult> AddEntity([FromBody] UserInfoAddRequest entityObject)
        {
            UserInfo dataObject = new UserInfo(entityObject);

            APIResponse = await baseService.AddEntity(dataObject);

            return(Ok(APIResponse));
        }
 public MessageModel <string> Post([FromBody] MngAdmin model)
 {
     MngAdminService.AddEntity(model);
     return(new MessageModel <string>
     {
         success = true,
         msg = "添加成功"
     });
 }
示例#3
0
 public MessageModel <string> Post([FromBody] PdProduct model)
 {
     PdProductService.AddEntity(model);
     return(new MessageModel <string>
     {
         success = true,
         msg = "添加成功"
     });
 }
示例#4
0
        /// <summary>
        /// 添加模板文件
        /// </summary>
        /// <typeparam name="T">模板类型</typeparam>
        /// <param name="templet">模板实体</param>
        /// <param name="request">请求对象,用于获取上传的文件</param>
        /// <param name="service">数据服务对象</param>
        /// <param name="templetType">模板类型,首字母大写</param>
        /// <returns>插入结果</returns>
        public StateMessage SaveTemplet <T>(TempletForJson templet, HttpRequest request, IBaseService <T> service, string templetType) where T : BaseTemplet, new()
        {
            UserForTemplet user = new ValidateToken().CheckUser(templet.TokenValue.Trim());//token验证用户

            if (user.StateCode != StateCode.normal)
            {
                return new StateMessage()
                       {
                           StateCode = user.StateCode, StateDescription = user.StateDescription
                       }
            }
            ;
            UserInfo userInfo = ServiceSessionFactory.ServiceSession.UserInfoService.LoadEntity(u => u.ID == user.ID).FirstOrDefault();//查询用户以写数据库

            if (userInfo == null)
            {
                return new StateMessage()
                       {
                           StateCode = StateCode.noUser, StateDescription = "token所指示的用户不存在"
                       }
            }
            ;
            if ((userInfo.UserAuth != (UserAuth.Admin | UserAuth.Uploader)) && templet.Accessibility == Accessibility.Protected)//验证用户权限
            {
                return new StateMessage()
                       {
                           StateCode = StateCode.permissionDenied, StateDescription = "权限不足"
                       }
            }
            ;
            lock (ServiceSessionFactory.ServiceSession)                        //加锁防止请求并发时ID重复
            {
                int tempID = service.LoadEntity(w => true).Max(w => w.ID) + 1; //取数据库中最大的ID+1作为新模板的ID,

                T word = new T()
                {
                    ID                  = tempID,
                    TempletName         = templet.TempletName,
                    TempletIntroduction = templet.TempletIntroduction,
                    Accessibility       = templet.Accessibility,
                    ImagePath           = "/Content/" + templetType + "/w" + tempID + ".png",
                    FilePath            = "/Content/" + templetType + "/w" + tempID + ".docx",
                    ModTime             = DateTime.Now,
                    User                = userInfo,
                    Organization        = userInfo.Organization ?? new OrganizationInfo()
                    {
                        ID = new Guid()
                    }
                };//实例化插入对象
                if (request.Files.Count != 2)
                {
                    return new StateMessage()
                           {
                               StateCode = StateCode.noRequestError, StateDescription = "请求无附加文件或附加文件数量有误"
                           }
                }
                ;
                request.Files[0].SaveAs(request.MapPath("/Content/" + templetType + "/w" + tempID + ".docx"));
                request.Files[1].SaveAs(request.MapPath("/Content/" + templetType + "/w" + tempID + ".png"));//存储文件
                service.AddEntity(word);
            }
            return(new StateMessage()
            {
                StateCode = StateCode.normal, StateDescription = "上传成功"
            });
        }
示例#5
0
 public IActionResult Post([FromBody] TEntity entity)
 {
     return(Ok(_baseService.AddEntity(entity)));
 }