コード例 #1
0
        /// <summary>
        /// Update by providing a populated data row container
        /// </summary>
        /// <param name="row">The table row data to use</param>
        /// <returns>The number of rows affected.</returns>
        public virtual int Update(OrganizationContract row)
        {
            var rowCount = 0;

            VotingInfoDb.ConnectThen(x =>
            {
                using (
                    var cmd = new SqlCommand("[Data].[Organization_Update]", x)
                {
                    CommandType = CommandType.StoredProcedure,
                    CommandTimeout = DefaultCommandTimeout
                })
                {
                    cmd.Parameters.AddRange(new[] {
                        new SqlParameter("@OrganizationId", row.OrganizationId)
                        ,
                        new SqlParameter("@ContentInspectionId", row.ContentInspectionId)
                        ,
                        new SqlParameter("@OrganizationName", row.OrganizationName)
                    });

                    rowCount = cmd.ExecuteNonQuery();
                }
            });


            return(rowCount);
        }
コード例 #2
0
        /// <summary>
        /// Insert by providing a populated data row container
        /// </summary>
        /// <param name="row">The table row data to use</param>
        /// <returns>1, if insert was successful</returns>
        public int Insert(OrganizationContract row)
        {
            int?result = null;

            VotingInfoDb.ConnectThen(x =>
            {
                using (
                    var cmd = new SqlCommand("[Data].[Organization_Insert]", x)
                {
                    CommandType = CommandType.StoredProcedure,
                    CommandTimeout = DefaultCommandTimeout
                })
                {
                    cmd.Parameters.AddRange(new[] {
                        new SqlParameter("@ContentInspectionId", row.ContentInspectionId)
                        ,
                        new SqlParameter("@OrganizationName", row.OrganizationName)
                    });

                    result             = (int?)cmd.ExecuteScalar();
                    row.OrganizationId = result;
                }
            });
            return(result != null ? 1 : 0);
        }
コード例 #3
0
ファイル: Organization.cs プロジェクト: AnikinViktor/IVR
 public static List<Organization> Convert(OrganizationContract[] organizations)
 {
     List<Organization> result = new List<Organization>();
     for (int i = 0; i <= organizations.Length - 1; ++i)
     {
         result.Add(new Organization(organizations[i]));
     }
     return result;
 }
コード例 #4
0
 /// <summary>
 /// Saves the row, either by inserting (when the identity key is null) or by updating (identity key has value).
 /// </summary>
 /// <param name="row">The data to save</param>
 /// <param name="connection">The SqlConnection to use</param>
 /// <param name="transaction">The SqlTransaction to use</param>
 /// <returns>The number of rows affected.</returns>
 public static int SaveNow(OrganizationContract row, SqlConnection connection, SqlTransaction transaction)
 {
     if (row.OrganizationId == null)
     {
         return(InsertNow(row, connection, transaction));
     }
     else
     {
         return(UpdateNow(row, connection, transaction));
     }
 }
コード例 #5
0
 /// <summary>
 /// Saves the row, either by inserting (when the identity key is null) or by updating (identity key has value).
 /// </summary>
 /// <param name="row">The data to save</param>
 /// <returns>The number of rows affected.</returns>
 public static int SaveNow(OrganizationContract row)
 {
     if (row.OrganizationId == null)
     {
         return(InsertNow(row));
     }
     else
     {
         return(UpdateNow(row));
     }
 }
コード例 #6
0
        /// <summary>
        /// 更改机构
        /// </summary>
        /// <param name="organizationContract"></param>
        /// <returns></returns>
        public ResultContract <bool> UpdateOrganization(OrganizationContract organizationContract)
        {
            var result = new ResultContract <bool>()
            {
                Code = 0, Msg = "", Data = true
            };
            var organizationEntity = organizationContract.MapTo <OrganizationEntity>();

            this._dbContext.Organization.Update(organizationEntity);
            this._dbContext.SaveChanges();

            return(result);
        }
コード例 #7
0
        /// <summary>
        /// Saves the row, either by inserting (when the identity key is null) or by updating (identity key has value).
        /// </summary>
        /// <param name="row">The data to save</param>
        /// <param name="connection">The SqlConnection to use</param>
        /// <param name="transaction">The SqlTransaction to use</param>
        /// <returns>The number of rows affected.</returns>
        public virtual int Save(OrganizationContract row, SqlConnection connection, SqlTransaction transaction)
        {
            if (row == null)
            {
                return(0);
            }
            if (row.OrganizationId != null)
            {
                return(Update(row, connection, transaction));
            }

            return(Insert(row, connection, transaction));
        }
コード例 #8
0
        /// <summary>
        /// Saves the row, either by inserting (when the identity key is null) or by updating (identity key has value).
        /// </summary>
        /// <param name="row">The data to save</param>
        /// <returns>The number of rows affected.</returns>
        public virtual int Save(OrganizationContract row)
        {
            if (row == null)
            {
                return(0);
            }
            if (row.OrganizationId != null)
            {
                return(Update(row));
            }

            return(Insert(row));
        }
コード例 #9
0
 public async Task <Contracts.ResultContract <bool> > AddOrganization([FromBody] OrganizationContract organization)
 {
     try
     {
         return(_organizationService.AddOrganization(organization));
     }
     catch (Exception)
     {
         return(new Contracts.ResultContract <bool>()
         {
             Code = -1, Msg = "服务异常"
         });
     }
 }
コード例 #10
0
        /// <summary>
        /// 增加机构
        /// </summary>
        /// <param name="organizationContract"></param>
        /// <returns></returns>
        public ResultContract <bool> AddOrganization(OrganizationContract organizationContract)
        {
            var result = new ResultContract <bool>()
            {
                Code = 0, Msg = "", Data = true
            };
            var organizationEntity = organizationContract.MapTo <OrganizationEntity>();

            organizationEntity.OrganizationId = Guid.NewGuid();
            organizationEntity.CreateTime     = DateTime.Now;
            this._dbContext.Organization.Add(organizationEntity);
            this._dbContext.SaveChanges();

            return(result);
        }
コード例 #11
0
        /// <summary>
        /// Delete by providing a populated data contract
        /// </summary>
        /// <param name="row">The table row data to use</param>
        /// <param name="connection">The SqlConnection to use</param>
        /// <param name="transaction">The SqlTransaction to use</param>
        /// <returns>The number of rows affected.</returns>
        public virtual int Delete(OrganizationContract row, SqlConnection connection, SqlTransaction transaction)
        {
            var rowCount = 0;

            using (
                var cmd = new SqlCommand("[Data].[Organization_Delete]", connection)
            {
                CommandType = CommandType.StoredProcedure, Transaction = transaction
            })
            {
                cmd.Parameters.AddRange(new[] {
                    new SqlParameter("@OrganizationId", row.OrganizationId)
                });

                rowCount = cmd.ExecuteNonQuery();
            }


            return(rowCount);
        }
コード例 #12
0
        /// <summary>
        /// Insert by providing a populated data contract
        /// </summary>
        /// <param name="row">The table row data to use</param>
        /// <param name="connection">The SqlConnection to use</param>
        /// <param name="transaction">The SqlTransaction to use</param>
        /// <returns>1, if insert was successful</returns>
        public int Insert(OrganizationContract row, SqlConnection connection, SqlTransaction transaction)
        {
            int?result = null;

            using (
                var cmd = new SqlCommand("[Data].[Organization_Insert]", connection)
            {
                CommandType = CommandType.StoredProcedure, Transaction = transaction
            })
            {
                cmd.Parameters.AddRange(new[] {
                    new SqlParameter("@ContentInspectionId", row.ContentInspectionId)
                    ,
                    new SqlParameter("@OrganizationName", row.OrganizationName)
                });

                result             = (int?)cmd.ExecuteScalar();
                row.OrganizationId = result;
            }
            return(result != null ? 1 : 0);
        }
コード例 #13
0
 /// <summary>
 /// Insert by providing a populated data row container
 /// </summary>
 /// <param name="row">The table row data to use</param>
 /// <returns>The number of rows affected.</returns>
 public static int InsertNow(OrganizationContract row)
 {
     return((new OrganizationLogic()).Insert(row));
 }
コード例 #14
0
 /// <summary>
 /// Insert by providing a populated data contract
 /// </summary>
 /// <param name="row">The table row data to use</param>
 /// <param name="connection">The SqlConnection to use</param>
 /// <param name="transaction">The SqlTransaction to use</param>
 /// <returns>The number of rows affected.</returns>
 public static int InsertNow(OrganizationContract row, SqlConnection connection, SqlTransaction transaction)
 {
     return((new OrganizationLogic()).Insert(row, connection, transaction));
 }
コード例 #15
0
ファイル: Organization.cs プロジェクト: AnikinViktor/IVR
 public Organization(OrganizationContract group)
 {
     this.ID = group.ID;
     this.Name = group.Name;
 }
コード例 #16
0
        /// <summary>
        /// 验证参数
        /// </summary>
        /// <param name="data"></param>
        /// <param name="result"></param>
        private void CheckParameter(BaseUploadContract data, ref ResultContract <string> result, ref OrganizationContract orgInfo)
        {
            //验证appid
            if (string.IsNullOrWhiteSpace(data.AppId) || !_uploadHandService.CheckAppId(data.AppId))
            {
                result.Code = -1;
                result.Msg  = "系统没有注册!";
            }

            //验证组织机构id
            if (data.OrgId == null)
            {
                result.Code = -1;
                result.Msg  = "请输入组织机构id!";
            }

            orgInfo = _uploadHandService.CheckOrgInfo(data.OrgId.GetValueOrDefault());
            if (orgInfo == null)
            {
                result.Code = -1;
                result.Msg  = "组织机构输入错误!";
            }

            //验证资源类型
            if (data.ThemeType != ThemeTypeEnum.ThemeEvent.GetIntValue() && data.ThemeType != ThemeTypeEnum.ThemeResource.GetIntValue())
            {
                result.Code = -1;
                result.Msg  = "资源类型错误!";
            }
        }
コード例 #17
0
 /// <summary>
 /// Delete by providing a populated data contract
 /// </summary>
 /// <param name="row">The table row data to use</param>
 /// <param name="connection">The SqlConnection to use</param>
 /// <param name="transaction">The SqlTransaction to use</param>
 /// <returns>The number of rows affected.</returns>
 public static int DeleteNow(OrganizationContract row, SqlConnection connection, SqlTransaction transaction)
 {
     return((new OrganizationLogic()).Delete(row, connection, transaction));
 }
コード例 #18
0
 /// <summary>
 /// Delete by providing a populated data row container
 /// </summary>
 /// <param name="row">The table row data to use</param>
 /// <returns>The number of rows affected.</returns>
 public static int DeleteNow(OrganizationContract row)
 {
     return((new OrganizationLogic()).Delete(row));
 }
コード例 #19
0
        public async Task <ResultContract <string> > UploadFile(BaseUploadContract data)
        {
            var result = new ResultContract <string>()
            {
                Code = 0, Msg = "上传成功"
            };

            try
            {
                //验证参数
                var orgInfo = new OrganizationContract();
                this.CheckParameter(data, ref result, ref orgInfo);
                if (result.Code == -1)
                {
                    return(result);
                }

                List <UploadContract> fileList = new List <UploadContract>();
                var files   = Request.Form.Files;
                var groupId = Guid.NewGuid().ToString();
                int order   = 1;
                foreach (var file in files)
                {
                    var fileModel = new UploadContract()
                    {
                        UserId      = data.UserId,
                        OrgId       = data.OrgId,
                        AppId       = data.AppId,
                        Tags        = data.Tags,
                        UploadTime  = DateTime.Now,
                        DisplayName = data.DisplayName,
                        Remark      = data.Remark,
                        OrgName     = orgInfo.OrganizationName,
                        Order       = order,
                        ThemeType   = data.ThemeType
                    };

                    //分组id
                    fileModel.GroupId = groupId;
                    var fileData = new MultipartFormDataContent();

                    //判断文件夹是否存在
                    if (!Directory.Exists(uploadFilePath))
                    {
                        Directory.CreateDirectory(uploadFilePath);
                    }
                    var imgPath = AppDomain.CurrentDomain.BaseDirectory + ConfigHelper.ReadConfigByName("ImgsPath");
                    if (!Directory.Exists(imgPath))
                    {
                        Directory.CreateDirectory(imgPath);
                    }

                    fileModel.FileName = file.FileName;
                    var lastName = file.FileName.Substring(file.FileName.LastIndexOf(".") + 1, (file.FileName.Length - file.FileName.LastIndexOf(".") - 1)); //扩展名
                    fileModel.FileId      = Guid.NewGuid();
                    fileModel.NewFileName = fileModel.FileId + "." + lastName;
                    var fileLocalFullName = uploadFilePath + Path.DirectorySeparatorChar + fileModel.NewFileName;
                    var stream            = file.OpenReadStream();
                    //文件保存到本地
                    double fileSize = 0;
                    //保存文件
                    FileHelper.SavaFile(fileLocalFullName, stream, ref fileSize);
                    //文件上传成功 修改model
                    fileModel.IsUpload = false;
                    fileModel.Url      = fileLocalFullName;
                    fileModel.FileType = lastName;
                    //组织名称。后期加上
                    //判断文件大小
                    double uploadLimitSize = 0;
                    double.TryParse(ConfigHelper.ReadConfigByName("UploadLimitSizeM"), out uploadLimitSize);

                    //如果是视频截取封面
                    if (CommonDictionary.GetInstance().VideoType.Count(d => d.ToLower() == lastName.ToLower()) > 0)
                    {
                        var thumbnailPath = AliyunOSSHepler.GetInstance().GetPicFromVideo(fileLocalFullName, imgPath + Path.DirectorySeparatorChar + fileModel.FileId + ".jpg", "1");
                        var thumbnailUrl  = "";
                        var isUpload      = AliyunOSSHepler.GetInstance().UploadFiles(imgPath, fileModel.FileId + ".jpg", ref
                                                                                      thumbnailUrl, true);

                        fileModel.ThumbnailUrl = thumbnailPath;

                        if (isUpload && !string.IsNullOrWhiteSpace(thumbnailUrl))
                        {
                            fileModel.ThumbnailUrl = thumbnailUrl;
                        }
                        else
                        {
                            fileModel.IsFailure = true;
                            this._uploadHandService.SavaTagsFile(fileModel);
                            //把文件 移动到错误文件 文件夹
                            System.IO.File.Move(uploadFilePath + Path.DirectorySeparatorChar + fileModel.NewFileName, FailurePath + Path.DirectorySeparatorChar + fileModel.NewFileName);
                            result.Code = -1;
                            result.Msg  = "截图失败";
                            return(result);
                        }
                    }

                    //如果断网把标签和文件都存到本地
                    if (!CommonDictionary.GetInstance().KafkaIsOnline)
                    {
                        this._uploadHandService.SavaTagsFile(fileModel);
                    }
                    else
                    {
                        //如果文件大小比预设大小 小 直接上云
                        if (fileSize < uploadLimitSize)
                        {
                            var url = "";
                            fileModel.IsUpload = AliyunOSSHepler.GetInstance().UploadFiles(uploadFilePath, fileModel.NewFileName, ref
                                                                                           url, false);

                            //如果上传失败  标签存本地
                            if (!fileModel.IsUpload)
                            {
                                fileModel.IsFailure = true;
                                this._uploadHandService.SavaTagsFile(fileModel);
                                //把文件 移动到错误文件 文件夹
                                System.IO.File.Move(uploadFilePath + Path.DirectorySeparatorChar + fileModel.NewFileName, FailurePath + Path.DirectorySeparatorChar + fileModel.NewFileName);
                            }
                            else
                            {
                                fileModel.Url = url;
                            }
                        }

                        fileList.Add(fileModel);
                        order++;
                    }
                }

                ////把标签 推送到总署
                KafKaContract kafkaModel = new KafKaContract();
                if (fileList.Count > 1)  //批量添加
                {
                    kafkaModel.MsgCode = KafkaMsgCodeEnum.AddList;
                    kafkaModel.Msg     = SerializeHelper.serializeToString(fileList);
                    KafKaLogic.GetInstance().Push(kafkaModel, KafkaTopic);
                }
                else if (fileList.Count() == 1) //单个文件添加
                {
                    kafkaModel.MsgCode  = KafkaMsgCodeEnum.Add;
                    fileList[0].GroupId = Guid.NewGuid().ToString();
                    kafkaModel.Msg      = SerializeHelper.serializeToString(fileList[0]);
                    KafKaLogic.GetInstance().Push(kafkaModel, KafkaTopic);
                }
            }
            catch (Exception e)
            {
                LogHelper.logError("上传文件失败:" + e.StackTrace);
                result.Code = -1;
                result.Msg  = e.Message;
            }

            return(result);
        }