public ActionResultVM Add(Domain.GuffRecord mo) { var vm = new ActionResultVM(); try { var uinfo = new Application.UserAuthService(HttpContext).Get(); if (string.IsNullOrWhiteSpace(mo.GrContent) && string.IsNullOrWhiteSpace(mo.GrImage) && string.IsNullOrWhiteSpace(mo.GrAudio) && string.IsNullOrWhiteSpace(mo.GrVideo)) { vm.Code = 1; vm.Msg = "内容不能为空(内容、图片、音频、视频 至少有一项有内容)"; } else if (string.IsNullOrWhiteSpace(mo.GrTag)) { vm.Code = 2; vm.Msg = "标签不能为空"; } else if (uinfo.UserId == 0) { vm.Set(ARTag.unauthorized); } else { if (GlobalTo.GetValue <bool>("Common:MailValid") && db.UserInfo.Find(uinfo.UserId).UserMailValid != 1) { vm.Code = 1; vm.Msg = "请先验证邮箱"; } else { var now = DateTime.Now; mo.Uid = uinfo.UserId; mo.GrId = Core.UniqueTo.LongId().ToString(); mo.GrCreateTime = now; mo.GrUpdateTime = now; mo.GrStatus = 1; mo.GrReadNum = 0; mo.GrLaud = 0; mo.GrMark = 0; mo.GrReplyNum = 0; mo.GrOpen ??= 1; mo.GrTypeName = Fast.ParsingTo.JsSafeJoin(mo.GrTypeName); mo.GrTypeValue = Fast.ParsingTo.JsSafeJoin(mo.GrTypeValue); mo.GrObject = Fast.ParsingTo.JsSafeJoin(mo.GrObject); mo.GrImage = Fast.ParsingTo.JsSafeJoin(mo.GrImage); mo.GrAudio = Fast.ParsingTo.JsSafeJoin(mo.GrAudio); mo.GrVideo = Fast.ParsingTo.JsSafeJoin(mo.GrVideo); mo.GrFile = Fast.ParsingTo.JsSafeJoin(mo.GrFile); mo.GrTag = Fast.ParsingTo.JsSafeJoin(mo.GrTag); db.GuffRecord.Add(mo); int num = db.SaveChanges(); vm.Data = mo.GrId; vm.Set(num > 0); } } } catch (Exception ex) { vm.Set(ex); Filters.FilterConfigs.WriteLog(HttpContext, ex); } return(vm); }
public ActionResultVM Update(Domain.GuffRecord mo) { var vm = new ActionResultVM(); try { var uinfo = new Application.UserAuthService(HttpContext).Get(); if (string.IsNullOrWhiteSpace(mo.GrContent) && string.IsNullOrWhiteSpace(mo.GrImage) && string.IsNullOrWhiteSpace(mo.GrAudio) && string.IsNullOrWhiteSpace(mo.GrVideo)) { vm.Code = 1; vm.Msg = "内容不能为空(内容、图片、音频、视频 至少有一项有内容)"; } else if (string.IsNullOrWhiteSpace(mo.GrTag)) { vm.Code = 2; vm.Msg = "标签不能为空"; } else if (uinfo.UserId == 0) { vm.Set(ARTag.unauthorized); } else { var currMo = db.GuffRecord.Find(mo.GrId); if (currMo == null) { vm.Set(ARTag.invalid); } else if (currMo.Uid != uinfo.UserId) { vm.Set(ARTag.unauthorized); } else { currMo.GrTypeName = Fast.ParsingTo.JsSafeJoin(mo.GrTypeName); currMo.GrTypeValue = Fast.ParsingTo.JsSafeJoin(mo.GrTypeValue); currMo.GrObject = Fast.ParsingTo.JsSafeJoin(mo.GrObject); currMo.GrContent = mo.GrContent; currMo.GrContentMd = mo.GrContentMd; currMo.GrImage = Fast.ParsingTo.JsSafeJoin(mo.GrImage); currMo.GrAudio = Fast.ParsingTo.JsSafeJoin(mo.GrAudio); currMo.GrVideo = Fast.ParsingTo.JsSafeJoin(mo.GrVideo); currMo.GrFile = Fast.ParsingTo.JsSafeJoin(mo.GrFile); currMo.GrRemark = mo.GrRemark; currMo.GrTag = mo.GrTag; currMo.GrUpdateTime = DateTime.Now; currMo.GrOpen = mo.GrOpen ?? 1; db.Update(currMo); int num = db.SaveChanges(); vm.Data = mo.GrId; vm.Set(num > 0); } } } catch (Exception ex) { vm.Set(ex); Filters.FilterConfigs.WriteLog(HttpContext, ex); } return(vm); }
public SharedResultVM Add([FromForm] Domain.GuffRecord mo) { var vm = new SharedResultVM(); try { var uinfo = Apps.LoginService.Get(HttpContext); if (string.IsNullOrWhiteSpace(mo.GrContent) && string.IsNullOrWhiteSpace(mo.GrImage) && string.IsNullOrWhiteSpace(mo.GrAudio) && string.IsNullOrWhiteSpace(mo.GrVideo)) { vm.Code = 1; vm.Msg = "内容不能为空(内容、图片、音频、视频 至少有一项有内容)"; } else if (string.IsNullOrWhiteSpace(mo.GrTag)) { vm.Code = 2; vm.Msg = "标签不能为空"; } else if (uinfo.UserId == 0) { vm.Set(SharedEnum.RTag.unauthorized); } else { vm = Apps.LoginService.CompleteInfoValid(HttpContext); if (vm.Code == 200) { var now = DateTime.Now; mo.Uid = uinfo.UserId; mo.GrId = UniqueTo.LongId().ToString(); mo.GrCreateTime = now; mo.GrUpdateTime = now; mo.GrStatus = 1; mo.GrReadNum = 0; mo.GrLaud = 0; mo.GrMark = 0; mo.GrReplyNum = 0; mo.GrOpen ??= 1; mo.GrTypeName = ParsingTo.JsSafeJoin(mo.GrTypeName); mo.GrTypeValue = ParsingTo.JsSafeJoin(mo.GrTypeValue); mo.GrObject = ParsingTo.JsSafeJoin(mo.GrObject); mo.GrImage = ParsingTo.JsSafeJoin(mo.GrImage); mo.GrAudio = ParsingTo.JsSafeJoin(mo.GrAudio); mo.GrVideo = ParsingTo.JsSafeJoin(mo.GrVideo); mo.GrFile = ParsingTo.JsSafeJoin(mo.GrFile); mo.GrTag = ParsingTo.JsSafeJoin(mo.GrTag); db.GuffRecord.Add(mo); int num = db.SaveChanges(); vm.Data = mo.GrId; vm.Set(num > 0); } } } catch (Exception ex) { vm.Set(ex); Apps.FilterConfigs.WriteLog(HttpContext, ex); } return(vm); }