Ejemplo n.º 1
0
        public LeaveMessage AddInfo(CreateLeaveMessageInput input)
        {
            string guid = Guid.NewGuid().ToString();

            var leaveMessage = input.MapTo <LeaveMessage>();

            leaveMessage.LeaveTime = DateTime.Now;
            leaveMessage.Guid      = guid;

            db.LeaveMessages.Add(leaveMessage);

            if (input.Attach != null)
            {
                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    = 0,
                    CreateIP      = IPHelper.GetIPAddress,
                    ModuleType    = (int)AttachTypesEnum.留言附件
                });
            }

            return(db.SaveChanges() > 0 ? leaveMessage : null);
        }
Ejemplo n.º 2
0
        public ResponseInfoModel AddInfo([FromBody] CreateLeaveMessageInput input)
        {
            ResponseInfoModel json = new ResponseInfoModel()
            {
                Success = 1, Result = new object()
            };

            try
            {
                CheckModelState();

                var output = _leaveMessageService.AddInfo(input);
                if (output == null)
                {
                    json.Success = 0;
                    json.Result  = 1;
                }
                else
                {
                    _logService.Insert(new Log()
                    {
                        ActionContent = LocalizationConst.Insert,
                        SourceType    = _moduleName,
                        SourceID      = output.ID,
                        LogTime       = DateTime.Now,
                        LogUserID     = 0,
                        LogIPAddress  = IPHelper.GetIPAddress,
                    });
                }
            }
            catch (Exception e)
            {
                DisposeUserFriendlyException(e, ref json, "api/advice/add", LocalizationConst.InsertFail);
            }
            return(json);
        }