public bool Edit(RequestPersonDTO request, string operUserID, out string reason) { var rootpath = ConfigurationManager.AppSettings["rootpath"].ToString(); reason = ""; List <string> oldFiles = new List <string>(); Dictionary <string, string> copyfiles = new Dictionary <string, string>(); var needDelete = new List <VisitFile>(); var needNew = new List <VisitFile>(); using (var db = new DBEntities()) { var model = db.PersonInfos.Where(t => t.PersonID == request.PersonID).FirstOrDefault(); if (model != null) { if (!string.IsNullOrEmpty(model.CreateUserID) && model.CreateUserID != operUserID) { if (!CommonService.HasOtherDataAuth(operUserID, db)) { reason = "非本人创建的数据,不允许修改"; return(false); } } model.Birth = request.Birth; model.ContactAddress = request.ContactAddress; model.Department = request.Department; model.Duty = request.Duty; model.Email = request.Email; model.Fancy = request.Fancy; model.FromType = request.FromType; model.IDNumber = request.IDNumber; model.Mobile1 = request.Mobile1; model.Mobile2 = request.Mobile2; model.ModifyTime = DateTime.Now; model.ModifyUserID = operUserID; model.NameCN = request.NameCN; model.NameEN = request.NameEN; model.Nationality = request.Nationality; model.OrgID = request.OrgID; model.OrgName = request.OrgName; model.PassportCode = request.PassportCode; model.PassportDate = request.PassportDate; model.PassportSignAdress = request.PassportSignAdress; model.PassportSignDate = request.PassportSignDate; model.PassportType = request.PassportType; model.Sex = request.Sex; model.Taboo = request.Taboo; model.Tag = request.Tag; model.Tel1 = request.Tel1; model.Tel2 = request.Tel2; model.Title = request.Title; model.Remark = request.Remark; model.Intro = request.Intro; var passportFiles = db.VisitFiles.Where(t => t.OutID == model.PersonID && t.Type == "1").ToList(); CommonService.FindNewAndOld(passportFiles, request.PassportFiles, needDelete, needNew); CommonService.HandleFiles(needDelete, needNew, oldFiles, model.PersonID, "1", copyfiles, db); var photoFiles = db.VisitFiles.Where(t => t.OutID == model.PersonID && t.Type == "2").ToList(); CommonService.FindNewAndOld(photoFiles, request.PhotoFiles, needDelete, needNew); CommonService.HandleFiles(needDelete, needNew, oldFiles, model.PersonID, "2", copyfiles, db); var idNumberFiles = db.VisitFiles.Where(t => t.OutID == model.PersonID && t.Type == "3").ToList(); CommonService.FindNewAndOld(idNumberFiles, request.IDNumberFiles, needDelete, needNew); CommonService.HandleFiles(needDelete, needNew, oldFiles, model.PersonID, "3", copyfiles, db); } else { model = request.Map <RequestPersonDTO, PersonInfo>(); model.CreateTime = DateTime.Now; model.CreateUserID = operUserID; CommonService.HandleFiles(null, request.PassportFiles, oldFiles, model.PersonID, "1", copyfiles, db); CommonService.HandleFiles(null, request.IDNumberFiles, oldFiles, model.PersonID, "2", copyfiles, db); CommonService.HandleFiles(null, request.PhotoFiles, oldFiles, model.PersonID, "3", copyfiles, db); db.PersonInfos.Add(model); } var ret = db.SaveChanges() > 0; if (ret) { foreach (var item in oldFiles) { try { File.Delete(item); } catch (Exception ex) { } } foreach (var item in copyfiles) { try { File.Move(item.Key, item.Value); } catch (Exception ex) { } } } return(ret); } }
public bool Edit(RequestOrgDTO request, string operUserID, out string reason) { reason = ""; List <string> oldFiles = new List <string>(); Dictionary <string, string> copyfiles = new Dictionary <string, string>(); var needDelete = new List <VisitFile>(); var needNew = new List <VisitFile>(); using (var db = new DBEntities()) { var model = db.Orgnazitions.Where(t => t.OrgID == request.OrgID).FirstOrDefault(); if (model != null) { if (!string.IsNullOrEmpty(model.CreateUserID) && model.CreateUserID != operUserID) { if (!CommonService.HasOtherDataAuth(operUserID, db)) { reason = "非本人创建的数据,不允许修改"; return(false); } } model.OrgID = request.OrgID; model.OrgInfo = request.OrgInfo; model.OrgHistory = request.OrgHistory; model.OrgName = request.OrgName; model.OrgNameEN = request.OrgNameEN; model.OrgType = request.OrgType; model.Province = request.Province; model.Remark = request.Remark; model.ShortNameCN = request.ShortNameCN; model.ShortNameEN = request.ShortNameEN; model.Tag = request.Tag; model.Tel1 = request.Tel1; model.Tel2 = request.Tel2; model.Tax = request.Tax; model.WorkAddress = request.WorkAddress; model.WorkTime = request.WorkTime; model.Address = request.Address; model.ContactPerson1 = request.ContactPerson1; model.ContactPerson2 = request.ContactPerson2; model.Continent = request.Continent; model.Country = request.Country; model.Email1 = request.Email1; model.Email2 = request.Email2; model.FromType = request.FromType; model.Level = request.Level; model.OrgBack = request.OrgBack; model.ModifyUserID = operUserID; model.ModifyTime = DateTime.Now; var bjFiles = db.VisitFiles.Where(t => t.OutID == model.OrgID && t.Type == "20").ToList(); CommonService.FindNewAndOld(bjFiles, request.BJFiles, needDelete, needNew); CommonService.HandleFiles(needDelete, needNew, oldFiles, model.OrgID, "20", copyfiles, db); var otherFiles = db.VisitFiles.Where(t => t.OutID == model.OrgID && t.Type == "16").ToList(); CommonService.FindNewAndOld(otherFiles, request.OtherFiles, needDelete, needNew); CommonService.HandleFiles(needDelete, needNew, oldFiles, model.OrgID, "16", copyfiles, db); } else { var exits = db.Orgnazitions.Where(t => t.OrgName == request.OrgName || t.OrgNameEN == request.OrgNameEN).FirstOrDefault(); if (exits != null) { reason = "机构名称重复"; return(false); } CommonService.HandleFiles(null, request.BJFiles, oldFiles, request.OrgID, "20", copyfiles, db); CommonService.HandleFiles(null, request.OtherFiles, oldFiles, request.OrgID, "16", copyfiles, db); model = request.Map <RequestOrgDTO, Orgnazition>(); model.CreateUserID = operUserID; model.CreateTime = DateTime.Now; db.Orgnazitions.Add(model); } var ret = db.SaveChanges() > 0; if (ret) { foreach (var item in oldFiles) { try { File.Delete(item); } catch (Exception ex) { } } foreach (var item in copyfiles) { try { File.Move(item.Key, item.Value); } catch (Exception ex) { } } } return(ret); } }