예제 #1
0
        public WildlifeManagement Add(CreateWildlifeManagementInput input)
        {
            string guid = Guid.NewGuid().ToString();
            var    wildlifeManagement = input.MapTo <WildlifeManagement>();

            wildlifeManagement.CreatTime = DateTime.Now;
            wildlifeManagement.CreateIP  = IPHelper.GetIPAddress;
            wildlifeManagement.FileID    = guid;

            db.WildlifeManagements.Add(wildlifeManagement);

            if (input.Attach != null && !string.IsNullOrEmpty(input.Attach.HashValue))
            {
                db.ArticleAttaches.Add(new ArticleAttach()
                {
                    HashValue     = input.Attach.HashValue,
                    ArticleGuid   = guid,
                    AttachName    = input.Attach.AttachName,
                    AttachNewName = input.Attach.AttachNewName,
                    AttachUrl     = input.Attach.AttachUrl,
                    AttachFormat  = input.Attach.AttachFormat,
                    AttachIndex   = 1,
                    AttachBytes   = input.Attach.AttachBytes,
                    AttachType    = input.Attach.AttachType,
                    CreateTime    = DateTime.Now,
                    CreateUser    = input.CreatUser,
                    CreateIP      = IPHelper.GetIPAddress,
                    ModuleType    = (int)AttachTypesEnum.动植物管理附件
                });
            }

            return(db.SaveChanges() > 0 ? wildlifeManagement : null);
        }
예제 #2
0
        public ResponseInfoModel Add([FromBody] CreateWildlifeManagementInput input)
        {
            ResponseInfoModel json = new ResponseInfoModel()
            {
                Success = 1, Result = new object()
            };

            try
            {
                CheckModelState();

                var entity = _wildlifeManagerService.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/add", LocalizationConst.InsertFail);
            }
            return(json);
        }