public List <repairPhoto> getPhotoListById(int detailID) { List <repairPhoto> resultList = new List <repairPhoto>(); var bucket = MongoHelper.getGridFSBucket(photosBucketName); var filter = Builders <GridFSFileInfo> .Filter.And( Builders <GridFSFileInfo> .Filter.Eq(x => x.Metadata["deleteStatus"], 1), Builders <GridFSFileInfo> .Filter.Eq(x => x.Metadata["detailID"], detailID)); //var filter1 = Builders<GridFSFileInfo>.Filter.ElemMatch("metadata", // Builders<BsonDocument>.Filter.And(Builders<BsonDocument>.Filter.Eq("deleteStatus", 1), // Builders<BsonDocument>.Filter.Eq("detailID", detailID))); var sort = Builders <GridFSFileInfo> .Sort.Descending(x => x.UploadDateTime); var options = new GridFSFindOptions { //Limit = 1, Sort = sort }; List <GridFSFileInfo> findResult = bucket.Find(filter, options).ToList(); foreach (var fileInfo in findResult) { if (fileInfo != null) { BsonDocument metaData = fileInfo.Metadata; repairPhoto pic = new repairPhoto(); pic.picID = fileInfo.Id; pic.picName = fileInfo.Filename; pic.detailID = metaData.GetValue("detailID").AsInt32; BsonDocument uploadUser = metaData.GetValue("uploadUser").AsBsonDocument; pic.roleID = uploadUser.GetValue("role").AsInt32; pic.userID = uploadUser.GetValue("user").AsInt32; resultList.Add(pic); } } return(resultList); }
protected void btnSubmit_Click(object sender, EventArgs e) { if (isInterrupted) { return; } projectDetailTable entity = detailBLL.getDetailInfoByID(Convert.ToInt32(tbDetailID.Text)); if (cmbFaultStatus.SelectedIndex > 0) { entity.faultStatus = Convert.ToInt32(cmbFaultStatus.SelectedValue); } if (cmbFaultType.SelectedIndex > 0) { entity.faultType = Convert.ToInt32(cmbFaultType.SelectedValue); } if (cmbSeverity.SelectedIndex > 0) { entity.severity = Convert.ToInt32(cmbSeverity.SelectedValue); } if (tbFaultDetail.Text != "") { entity.faultDetail = tbFaultDetail.Text; } if (tbAddRequirement.Text != "") { entity.add_requirement = tbAddRequirement.Text; } List <repairPhoto> newList = new List <repairPhoto>(); List <string> fnList_old = entity.photos.Select(photo => photo.picName).ToList(); foreach (UploadedFile uploadPic in RadAsyncUpload1.UploadedFiles) { repairPhoto pic = new repairPhoto(); pic.detailID = entity.detailID; if (Session["CurrentRole"] != null && Session["CurrentLoginUser"] != null) { pic.roleID = Convert.ToInt32(Session["CurrentRole"]); if (pic.roleID == 1) { pic.userID = (Session["CurrentLoginUser"] as employeeTable).employeeID; } else if (pic.roleID == 0) { pic.userID = (Session["CurrentLoginUser"] as repairmanTable).repairmanID; } } pic.picName = uploadPic.FileName; byte[] fileData = new byte[uploadPic.InputStream.Length]; uploadPic.InputStream.Read(fileData, 0, (int)uploadPic.InputStream.Length); pic.picData = fileData; pic.deleteStatus = 1; if (!fnList_old.Contains(pic.picName)) { newList.Add(pic); } } entity.photos = newList; //if (entity.photos == null) entity.photos = newList; //else //{ // foreach (var existPhoto in entity.photos) // { // if (newList.Contains(existPhoto)) continue; // else existPhoto.deleteStatus = 0; // } // //newList = newList.Except(entity.photos).ToList(); //取差集 // entity.photos = newList.Union(entity.photos).ToList(); //剔除重复项 //} if (detailBLL.updateDetailInfo(entity)) { RadAjaxManager1.Alert("更新成功"); setInputEnable(false); getRepairInfoByID(entity.detailID); } else { RadAjaxManager1.Alert("更新失败"); } }