Exemple #1
0
        public ViewSpot AddViewSpot(CreateViewSpotInput input)
        {
            string guid = Guid.NewGuid().ToString();

            var ViewSpot = input.MapTo <ViewSpot>();

            ViewSpot.CreatTime = DateTime.Now;
            ViewSpot.CreateIP  = IPHelper.GetIPAddress;
            ViewSpot.FileID    = guid;
            db.ViewSpots.Add(ViewSpot);

            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 ? ViewSpot : null);
        }
        public ResponseInfoModel Add([FromBody] CreateViewSpotInput input)
        {
            ResponseInfoModel json = new ResponseInfoModel()
            {
                Success = 1, Result = new object()
            };

            try
            {
                CheckModelState();

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