public WildlifeContent Add(CreateWildlifeContentInput input) { string guid = Guid.NewGuid().ToString(); var wildlifeContent = input.MapTo <WildlifeContent>(); wildlifeContent.CreateIP = IPHelper.GetIPAddress; wildlifeContent.CreatTime = DateTime.Now; wildlifeContent.FileID = guid; db.WildlifeContents.Add(wildlifeContent); int index = 1; if (input.Attachs != null) { foreach (var attach in input.Attachs) { if (attach != null) { db.ArticleAttaches.Add(new ArticleAttach() { HashValue = attach.HashValue, ArticleGuid = guid, AttachName = attach.AttachName, AttachNewName = attach.AttachNewName, AttachUrl = attach.AttachUrl, AttachFormat = attach.AttachFormat, AttachIndex = index++, AttachBytes = attach.AttachBytes, AttachType = attach.AttachType, CreateTime = DateTime.Now, CreateUser = input.CreatUser, CreateIP = IPHelper.GetIPAddress, ModuleType = (int)AttachTypesEnum.动植物管理详细附件 }); } } } return(db.SaveChanges() > 0 ? wildlifeContent : null); }
public ResponseInfoModel AddDetail([FromBody] CreateWildlifeContentInput input) { ResponseInfoModel json = new ResponseInfoModel() { Success = 1, Result = new object() }; try { CheckModelState(); var entity = _wildlifeContentService.Add(input); if (entity == null) { json.Success = 0; json.Result = LocalizationConst.InsertFail; } else { _logService.Insert(new Log() { ActionContent = LocalizationConst.Insert, SourceType = _moduleName, SourceID = entity.ID, LogTime = DateTime.Now, LogUserID = input.CreatUser, LogIPAddress = IPHelper.GetIPAddress, }); } } catch (Exception e) { DisposeUserFriendlyException(e, ref json, "api/wildlifemanager/adddetail", LocalizationConst.InsertFail); } return(json); }