Esempio n. 1
0
        public ResponseInfoModel Eidtdetail([FromBody] UpdateViewSpotContentInput input)
        {
            ResponseInfoModel json = new ResponseInfoModel()
            {
                Success = 1, Result = new object()
            };

            try
            {
                CheckModelState();

                if (!_viewSpotContentService.Edit(input))
                {
                    json.Success = 0;
                    json.Result  = LocalizationConst.UpdateFail;
                }
                else
                {
                    _logService.Insert(new Log()
                    {
                        ActionContent = LocalizationConst.Update,
                        SourceType    = _moduleName,
                        SourceID      = input.ID,
                        LogTime       = DateTime.Now,
                        LogUserID     = input.EditUser,
                        LogIPAddress  = IPHelper.GetIPAddress,
                    });
                }
            }
            catch (Exception e)
            {
                DisposeUserFriendlyException(e, ref json, "api/viewspot/eidtdetail", LocalizationConst.UpdateFail);
            }
            return(json);
        }
Esempio n. 2
0
        public bool Edit(UpdateViewSpotContentInput input)
        {
            var viewSpotContent = db.ViewSpotContents.Find(input.ID);

            if (viewSpotContent == null)
            {
                throw new UserFriendlyException(LocalizationConst.NoExist);
            }

            viewSpotContent          = input.MapTo(viewSpotContent);
            viewSpotContent.EditTime = DateTime.Now;
            viewSpotContent.EditIP   = IPHelper.GetIPAddress;

            var attachs = db.ArticleAttaches.Where(a => a.ArticleGuid == viewSpotContent.FileID && a.ModuleType == (int)AttachTypesEnum.景点详情附件);

            //为空全删除
            if (input.Attachs == null || !input.Attachs.Any())
            {
                if (attachs.Any())
                {
                    db.ArticleAttaches.RemoveRange(attachs);
                }
            }
            else
            {
                List <int> selectIds = input.Attachs.Select(a => a.ID).ToList();
                List <int> nowIDs    = attachs.Select(a => a.ID).ToList();
                List <int> deleteIDs = nowIDs.Except(selectIds).ToList();
                if (deleteIDs.Any())
                {
                    var deleteList = db.ArticleAttaches.Where(a => deleteIDs.Contains(a.ID));
                    if (deleteList.Any())
                    {
                        db.ArticleAttaches.RemoveRange(deleteList);
                    }
                }

                var aticlemax = db.ArticleAttaches.Where(a => a.ArticleGuid == viewSpotContent.FileID && a.ModuleType == (int)AttachTypesEnum.景点详情附件).Select(a => a.AttachIndex);

                int index = aticlemax.Any() ? aticlemax.Max() + 1 : 1;

                foreach (var attach in input.Attachs.Where(a => a.ID == 0))
                {
                    db.ArticleAttaches.Add(new ArticleAttach()
                    {
                        HashValue     = attach.HashValue,
                        ArticleGuid   = viewSpotContent.FileID,
                        AttachName    = attach.AttachName,
                        AttachNewName = attach.AttachNewName,
                        AttachUrl     = attach.AttachUrl,
                        AttachFormat  = attach.AttachFormat,
                        AttachIndex   = index++,
                        AttachBytes   = attach.AttachBytes,
                        AttachType    = attach.AttachType,
                        ModuleType    = (int)AttachTypesEnum.景点详情附件,
                        CreateTime    = DateTime.Now,
                        CreateUser    = input.EditUser,
                        CreateIP      = IPHelper.GetIPAddress
                    });
                }
            }

            db.Entry <ViewSpotContent>(viewSpotContent).State = EntityState.Modified;
            return(db.SaveChanges() > 0);
        }