Example #1
0
        public BizLogicMsg Save_RollFileAsTemplate(JsonMceAssetsRollFileTemplate item)
        {
            if (LocalMode)
            {
                BizLogicMsg msg = new BizLogicMsg();
                using (IDbConnection connection = IDALProvider.IDAL.PopConnection())
                {
                    using (IDbTransaction transaction = connection.BeginTransaction())
                    {
                        try
                        {
                            CauseObject_MCE_B_ASSETS_ROLLFILE pMCE_B_ASSETS_ROLLFILE = new CauseObject_MCE_B_ASSETS_ROLLFILE();
                            pMCE_B_ASSETS_ROLLFILE.BASE_ID = item.rollid;

                            DisplayObject_MCE_B_ASSETS_ROLLFILE[] listMCE_B_ASSETS_ROLLFILE = BizLogicObject_MCE_B_ASSETS_ROLLFILE.Proxy.Query(pMCE_B_ASSETS_ROLLFILE);

                            if (listMCE_B_ASSETS_ROLLFILE != null && listMCE_B_ASSETS_ROLLFILE.Length > 0)
                            {
                                EntityObject_MCE_B_ASSETS_FILETEMPLATE objTemplate = new EntityObject_MCE_B_ASSETS_FILETEMPLATE();
                                objTemplate.NAME     = item.name;
                                objTemplate.COMMENTS = item.comments;
                                HelperObject_MCE_B_ASSETS_FILETEMPLATE.Save(objTemplate, transaction);
                                foreach (DisplayObject_MCE_B_ASSETS_ROLLFILE displayObject_MCE_B_ASSETS_ROLLFILE in listMCE_B_ASSETS_ROLLFILE)
                                {
                                    EntityObject_MCE_B_ASSETS_FILETEMPLATE_D objTemplate_D = new EntityObject_MCE_B_ASSETS_FILETEMPLATE_D();
                                    objTemplate_D.CODE    = displayObject_MCE_B_ASSETS_ROLLFILE.CODE;
                                    objTemplate_D.NAME    = displayObject_MCE_B_ASSETS_ROLLFILE.NAME;
                                    objTemplate_D.BASE_ID = objTemplate.ID;
                                    HelperObject_MCE_B_ASSETS_FILETEMPLATE_D.Save(objTemplate_D, transaction);
                                }
                            }
                            else
                            {
                                throw new Exception("另存为文件数不能为0.");
                            }
                            transaction.Commit();
                        }
                        catch (Exception expt)
                        {
                            transaction.Rollback();
                            msg = new BizLogicMsg(false, expt.Message);
                            Error(expt);
                        }
                        finally
                        {
                            IDALProvider.IDAL.PushConnection(connection);
                        }
                    }
                }
                return(msg);
            }
            else
            {
                using (ServiceManager <ServiceContract_MCE_B_ASSETS_ROLL> smgr = new ServiceManager <ServiceContract_MCE_B_ASSETS_ROLL>(ServiceUri))
                {
                    return(smgr.Service.Save_RollFileAsTemplate(item));
                }
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            //允许跨域
            context.Response.AddHeader("Access-Control-Allow-Origin", "*");
            JSON_MSG jsonMsg = new JSON_MSG();

            try
            {
                context.Response.ContentType = "text/plain";
                HttpRequest request = context.Request;

                StringBuilder rsb       = new StringBuilder();
                int           bytelengg = (int)request.InputStream.Length;
                using (var reader = new StreamReader(request.InputStream, Encoding.UTF8))
                {
                    var read  = new Char[bytelengg];
                    var count = reader.Read(read, 0, bytelengg);
                    while (count > 0)
                    {
                        var str = new string(read, 0, count);
                        rsb.Append(str);
                        count = reader.Read(read, 0, bytelengg);
                    }
                    reader.Close();
                    reader.Dispose();
                    request.InputStream.Close();
                    request.InputStream.Dispose();
                }

                if (string.IsNullOrEmpty(rsb.ToString()))
                {
                    throw new Exception("参数错误.");
                }

                JsonMceAssetsRollFileTemplate item = JsonConvert.DeserializeObject <JsonMceAssetsRollFileTemplate>(rsb.ToString());

                if (item == null)
                {
                    throw new Exception("参数错误.");
                }

                if (string.IsNullOrEmpty(item.rollid))
                {
                    throw new Exception("案卷信息不能为空.");
                }

                if (string.IsNullOrEmpty(item.name))
                {
                    throw new Exception("模板名称不能为空.");
                }

                if (string.IsNullOrEmpty(item.comments))
                {
                    throw new Exception("模板说明不能为空.");
                }



                BizLogicMsg msg = BizLogicObject_MCE_B_ASSETS_ROLL.Proxy.Save_RollFileAsTemplate(item);
                if (!msg.Succeed)
                {
                    throw new Exception(msg.Message);
                }

                jsonMsg.Succeed = 1;
                jsonMsg.Message = msg.Message;
            }
            catch (Exception ex)
            {
                jsonMsg.Succeed = 0;
                jsonMsg.Message = ex.Message;
            }
            finally
            {
                context.Response.Write(JsonConvert.SerializeObject(jsonMsg));
                context.Response.End();
            }
        }