public ApiResult Edit([FromBody] RequestOrgDTO request) { OrgService orgService = new OrgService(); string reason; var ret = orgService.Edit(request, SecurityHelper.LoginUser.ID, out reason); if (!ret) { return(new ApiResult() { Status = EnumApiStatus.BizError, Msg = reason }); } else { return(ret.ToApiResult()); } }
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); } }