public ActionResultVM Connection(string type, int ac, string id) { var vm = new ActionResultVM(); try { var uinfo = new Application.UserAuthService(HttpContext).Get(); if (uinfo.UserId == 0) { vm.Set(ARTag.unauthorized); } else if (string.IsNullOrWhiteSpace(id)) { vm.Set(ARTag.invalid); } else if (!new List <string> { "add", "cancel" }.Contains(type)) { vm.Set(ARTag.invalid); } else if (!new List <int> { 1, 2 }.Contains(ac)) { vm.Set(ARTag.invalid); } else { using var db = new Data.ContextBase(); var currMo = db.GuffRecord.Find(id); if (currMo == null) { vm.Set(ARTag.invalid); } else { var ctype = Application.EnumService.ConnectionType.GuffRecord.ToString(); switch (type) { case "add": { if (db.UserConnection.Any(x => x.Uid == uinfo.UserId && x.UconnTargetType == ctype && x.UconnTargetId == id && x.UconnAction == ac)) { vm.Set(ARTag.exist); } else { //关联记录 var ucmo = new Domain.UserConnection() { UconnId = Core.UniqueTo.LongId().ToString(), Uid = uinfo.UserId, UconnTargetType = Application.EnumService.ConnectionType.GuffRecord.ToString(), UconnTargetId = id, UconnAction = ac, UconnCreateTime = DateTime.Now }; db.Add(ucmo); switch (ac) { case 1: currMo.GrLaud += 1; break; case 2: currMo.GrMark += 1; break; } db.Update(currMo); int num = db.SaveChanges(); vm.Set(num > 0); } } break; case "cancel": { var curruc = db.UserConnection.FirstOrDefault(x => x.Uid == uinfo.UserId && x.UconnTargetType == ctype && x.UconnTargetId == id && x.UconnAction == ac); if (curruc == null) { vm.Set(ARTag.invalid); } else { db.Remove(curruc); switch (ac) { case 1: currMo.GrLaud -= 1; break; case 2: currMo.GrMark -= 1; break; } db.Update(currMo); int num = db.SaveChanges(); vm.Set(num > 0); } } break; } } } } catch (Exception ex) { vm.Set(ex); Filters.FilterConfigs.WriteLog(HttpContext, ex); } return(vm); }