示例#1
0
        /// <summary>
        /// 阅读追加
        /// </summary>
        public void ListReadPlus()
        {
            int wid = Convert.ToInt32(RouteData.Values["id"]?.ToString());

            using var db = new ContextBase();
            var mo = db.UserWriting.Find(wid);

            if (mo != null)
            {
                mo.UwReadNum += 1;
                db.UserWriting.Update(mo);
                db.SaveChanges();
            }
        }
 public void Add(Domain.Entities.Anuncio Entity)
 {
     using (var db = new ContextBase(_OptionsBuider.Options))
     {
         var marca         = new SqlParameter("@marca", Entity.marca);
         var modelo        = new SqlParameter("@modelo", Entity.modelo);
         var versao        = new SqlParameter("@versao", Entity.versao);
         var ano           = new SqlParameter("@ano", Entity.ano);
         var quilometragem = new SqlParameter("@quilometragem", Entity.quilometragem);
         var observacao    = new SqlParameter("@observacao", Entity.observacao);
         db.Database.ExecuteSqlCommand("CreateAnuncio @marca, @modelo, @versao, @ano, @quilometragem, @observacao", marca, modelo, versao, ano, quilometragem, observacao);
         db.SaveChanges();
     }
 }
示例#3
0
        /// <summary>
        /// 替换链接
        /// </summary>
        /// <returns></returns>
        public static ActionResultVM ReplaceLink()
        {
            var vm = new ActionResultVM();

            try
            {
                var linka = "https://gs.zme.ink/";
                var linkb = "https://static.netnr.com/";

                using var db = new ContextBase();
                var list1 = db.UserWriting.Where(x => x.UwContent.Contains(linka) || x.UwContentMd.Contains(linka)).ToList();
                var list2 = db.UserReply.Where(x => x.UrContent.Contains(linka) || x.UrContentMd.Contains(linka)).ToList();
                var needo = false;
                foreach (var item in list1)
                {
                    item.UwContent   = item.UwContent.Replace(linka, linkb);
                    item.UwContentMd = item.UwContentMd.Replace(linka, linkb);
                }
                foreach (var item in list2)
                {
                    item.UrContent   = item.UrContent.Replace(linka, linkb);
                    item.UrContentMd = item.UrContentMd.Replace(linka, linkb);
                }
                if (list1.Count > 0)
                {
                    db.UserWriting.UpdateRange(list1);
                    needo = true;
                }
                if (list2.Count > 0)
                {
                    db.UserReply.UpdateRange(list2);
                    needo = true;
                }

                int num = 0;
                if (needo)
                {
                    num = db.SaveChanges();
                }

                vm.Set(ARTag.success);
                vm.Data = "受影响行数:" + num;
            }
            catch (Exception ex)
            {
                vm.Set(ex);
            }

            return(vm);
        }
        public ActionResultVM DelSysUser(string id)
        {
            var vm = new ActionResultVM();

            using (var db = new ContextBase())
            {
                var mo = db.SysUser.Find(id);
                db.SysUser.Remove(mo);
                int num = db.SaveChanges();
                vm.Set(num > 0);
            }

            return(vm);
        }
示例#5
0
        /// <summary>
        /// 处理操作记录
        /// </summary>
        /// <returns></returns>
        public static ActionResultVM HandleOperationRecord()
        {
            var vm = new ActionResultVM();

            try
            {
                if (GlobalTo.GetValue <bool>("Work:HOR:enable"))
                {
                    using var db = new ContextBase();

                    //处理Guff查询记录数
                    var ctype  = EnumService.ConnectionType.GuffRecord.ToString();
                    var listOr = db.OperationRecord.Where(x => x.OrType == ctype && x.OrMark == "default").ToList();
                    if (listOr.Count > 0)
                    {
                        var listAllId = string.Join(",", listOr.Select(x => x.OrSource).ToList()).Split(',').ToList();
                        var listid    = listAllId.Distinct();

                        var listmo = db.GuffRecord.Where(x => listid.Contains(x.GrId)).ToList();
                        foreach (var item in listmo)
                        {
                            item.GrReadNum += listAllId.GroupBy(x => x).FirstOrDefault(x => x.Key == item.GrId).Count();
                        }
                        db.GuffRecord.UpdateRange(listmo);

                        db.OperationRecord.RemoveRange(listOr);

                        int num = db.SaveChanges();

                        vm.Set(num > 0);
                        vm.Data = "受影响行数:" + num;
                    }
                    else
                    {
                        vm.Set(ARTag.lack);
                    }
                }
                else
                {
                    vm.Set(ARTag.lack);
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
            }

            return(vm);
        }
示例#6
0
        public int DelNote(int NotepadId)
        {
            int num = 0;

            using (var db = new ContextBase())
            {
                var mo = db.Notepad.Find(NotepadId);
                if (mo != null)
                {
                    db.Notepad.Remove(mo);
                    num = db.SaveChanges();
                }
            }
            return(num);
        }
示例#7
0
        public ActionResultVM SaveDocSet(Domain.DocSet mo)
        {
            var vm = new ActionResultVM();

            var uinfo = new Application.UserAuthService(HttpContext).Get();

            if (string.IsNullOrWhiteSpace(mo.DsCode))
            {
                mo.DsCode       = Core.UniqueTo.LongId().ToString();
                mo.Uid          = uinfo.UserId;
                mo.DsStatus     = 1;
                mo.DsCreateTime = DateTime.Now;

                db.DocSet.Add(mo);
            }
            else
            {
                var currmo = db.DocSet.Find(mo.DsCode);
                if (currmo.Uid != uinfo.UserId)
                {
                    vm.Set(ARTag.unauthorized);
                }

                currmo.DsName   = mo.DsName;
                currmo.DsRemark = mo.DsRemark;
                currmo.DsOpen   = mo.DsOpen;
                currmo.Spare1   = mo.Spare1;

                db.DocSet.Update(currmo);
            }
            var num = db.SaveChanges();

            vm.Set(num > 0);

            return(vm);
        }
示例#8
0
        public ActionResultVM Save(DocSetDetail mo)
        {
            var vm = new ActionResultVM();

            var uinfo = new Func.UserAuthAid(HttpContext).Get();

            using (var db = new ContextBase())
            {
                var ds = db.DocSet.Find(mo.DsCode);
                if (ds?.Uid != uinfo.UserId)
                {
                    vm.Set(ARTag.unauthorized);
                }
                else
                {
                    mo.DsdUpdateTime = DateTime.Now;
                    mo.Uid           = uinfo.UserId;

                    if (string.IsNullOrWhiteSpace(mo.DsdPid))
                    {
                        mo.DsdPid = Guid.Empty.ToString();
                    }

                    if (!mo.DsdOrder.HasValue)
                    {
                        mo.DsdOrder = 99;
                    }

                    if (string.IsNullOrWhiteSpace(mo.DsdId))
                    {
                        mo.DsdId         = Core.UniqueTo.LongId().ToString();
                        mo.DsdCreateTime = DateTime.Now;

                        db.DocSetDetail.Add(mo);
                    }
                    else
                    {
                        db.DocSetDetail.Update(mo);
                    }

                    int num = db.SaveChanges();
                    vm.Set(num > 0);
                    vm.data = mo.DsdId;
                }
            }

            return(vm);
        }
        public ActionResultVM DelSysDictionary(string id)
        {
            var vm = new ActionResultVM();

            using (var db = new ContextBase())
            {
                var mo = db.SysDictionary.Find(id);
                mo.SdStatus = -1;
                db.SysDictionary.Update(mo);
                int num = db.SaveChanges();

                vm.Set(num > 0);
            }

            return(vm);
        }
示例#10
0
        public ActionResultVM SaveCatalog(DocSetDetail mo)
        {
            var vm = new ActionResultVM();

            var uinfo = new Application.UserAuthService(HttpContext).Get();

            using var db = new ContextBase();
            var ds = db.DocSet.Find(mo.DsCode);

            if (ds?.Uid != uinfo.UserId)
            {
                vm.Set(ARTag.unauthorized);
                return(vm);
            }

            mo.DsdOrder ??= 99;
            mo.DsdUpdateTime = DateTime.Now;
            if (string.IsNullOrWhiteSpace(mo.DsdPid))
            {
                mo.DsdPid = Guid.Empty.ToString();
            }

            if (string.IsNullOrWhiteSpace(mo.DsdId))
            {
                mo.DsdId         = Guid.NewGuid().ToString();
                mo.DsdCreateTime = mo.DsdUpdateTime;
                mo.Uid           = uinfo.UserId;


                db.DocSetDetail.Add(mo);
            }
            else
            {
                var currmo = db.DocSetDetail.Where(x => x.DsdId == mo.DsdId).FirstOrDefault();
                currmo.DsdTitle = mo.DsdTitle;
                currmo.DsdOrder = mo.DsdOrder;
                currmo.DsdPid   = mo.DsdPid;

                db.DocSetDetail.Update(currmo);
            }
            int num = db.SaveChanges();

            vm.Set(num > 0);

            return(vm);
        }
示例#11
0
        public string BuildTableConfig(string names, int cover)
        {
            using (var db = new ContextBase())
            {
                var listName = names.Split(',');

                var dbtype      = db.TDB.ToString().ToLower();
                var dbname      = db.Database.GetDbConnection().Database;
                var sqltemplate = QueryScripts(db.TDB.ToString(), "config");

                foreach (var name in listName)
                {
                    var sql = sqltemplate.Replace("@DataBaseName", dbname).Replace("@TableName", name);

                    if (!string.IsNullOrWhiteSpace(sql))
                    {
                        var dt = new DataTable();

                        using (var dbsql = new ContextBase())
                        {
                            using (var conn = dbsql.Database.GetDbConnection())
                            {
                                conn.Open();
                                var cmd = conn.CreateCommand();
                                cmd.CommandText = sql;
                                dt.Load(cmd.ExecuteReader());
                            }
                        }

                        if (dt.Rows.Count > 0)
                        {
                            if (cover == 1)
                            {
                                var oldmo = db.SysTableConfig.Where(x => x.TableName == name).ToList();
                                db.SysTableConfig.RemoveRange(oldmo);
                            }

                            var listMo = dt.ToModel <SysTableConfig>();
                            db.SysTableConfig.AddRange(listMo);
                            db.SaveChanges();
                        }
                    }
                }
            }
            return("success");
        }
示例#12
0
        public void CreateFestival_FestivalForCreationAddressNull_ThrowsDbUpdateExceptionMissingForeignKey()
        {
            //Arrange
            Festival festivalEntity = new Festival
            {
                Title       = "Hellfest",
                Description = "",
                StartDate   = DateTimeMock.Object.Now.AddDays(5),
                EndDate     = DateTimeMock.Object.Now.AddDays(8)
            };

            //Act
            MedievalFestivalsRepositoryBase.AddFestival(festivalEntity);

            //Assert
            Assert.Throws <DbUpdateException>(() => ContextBase.SaveChanges());
        }
示例#13
0
        public ActionResultVM SaveTableConfig(string rows, int buildType)
        {
            var vm = new ActionResultVM();

            var listMo       = rows.ToEntitys <Domain.SysTableConfig>();
            var hasTableName = listMo.Select(x => x.TableName).ToList();

            switch (buildType)
            {
            //追加
            case 1:
            {
                var listField = db.SysTableConfig
                                .Where(x => hasTableName.Contains(x.TableName))
                                .Select(x => new { x.TableName, x.ColField }).ToList();
                for (int i = listMo.Count - 1; i >= 0; i--)
                {
                    if (listField.Any(x => x.TableName == listMo[i].TableName && x.ColField == listMo[i].ColField))
                    {
                        listMo.RemoveAt(i);
                    }
                }
            }
            break;

            //覆盖
            case 2:
            {
                var delstc = db.SysTableConfig.Where(x => hasTableName.Contains(x.TableName)).ToList();
                db.SysTableConfig.RemoveRange(delstc);
            }
            break;
            }

            if (listMo.Count > 0)
            {
                //主键统一用程序生成GUID覆盖
                listMo.ForEach(x => x.Id = Guid.NewGuid().ToString());
                db.SysTableConfig.AddRange(listMo);
            }

            vm.Data = db.SaveChanges();
            vm.Set(ARTag.success);

            return(vm);
        }
示例#14
0
        public string SaveSysTableConfig(SysTableConfig mo, string savetype)
        {
            int num = 0;

            using (var db = new ContextBase())
            {
                if (savetype == "add")
                {
                    db.SysTableConfig.Add(mo);
                }
                else
                {
                    db.SysTableConfig.Update(mo);
                }
                num = db.SaveChanges();
            }
            return(num > 0 ? "success" : "fail");
        }
示例#15
0
        public ActionResultVM UpdateUserSay(UserInfo mo)
        {
            var vm = new ActionResultVM();

            var uinfo = new UserAuthAid(HttpContext).Get();

            using (var db = new ContextBase())
            {
                var currmo = db.UserInfo.Find(uinfo.UserId);
                currmo.UserSay = mo.UserSay;
                db.UserInfo.Update(currmo);

                int num = db.SaveChanges();

                vm.Set(num > 0);
            }

            return(vm);
        }
示例#16
0
        public string SaveSysRole(SysRole mo, string savetype)
        {
            int num = 0;

            using (var db = new ContextBase())
            {
                if (savetype == "add")
                {
                    mo.CreateTime = DateTime.Now;
                    db.SysRole.Add(mo);
                }
                else
                {
                    db.SysRole.Update(mo);
                }
                num = db.SaveChanges();
            }
            return(num > 0 ? "success" : "fail");
        }
示例#17
0
        public string DelSysRole(string id)
        {
            int num = 0;

            using (var db = new ContextBase())
            {
                if (db.SysUser.Where(x => x.RoleId == id).Count() > 0)
                {
                    return("exists");
                }
                else
                {
                    var mo = db.SysRole.Find(id);
                    db.SysRole.Remove(mo);
                    num = db.SaveChanges();
                }
            }
            return(num > 0 ? "success" : "fail");
        }
        public ActionResultVM SaveSysUser(SysUser mo, string savetype, string OldUserPwd)
        {
            var vm = new ActionResultVM();

            using (var db = new ContextBase())
            {
                if (savetype == "add")
                {
                    if (db.SysUser.Where(x => x.SuName == mo.SuName).Count() > 0)
                    {
                        vm.Set(ARTag.exist);
                    }
                    else
                    {
                        mo.SuId         = Guid.NewGuid().ToString();
                        mo.SuCreateTime = DateTime.Now;
                        mo.SuPwd        = Core.CalcTo.MD5(mo.SuPwd);
                        db.SysUser.Add(mo);
                    }
                }
                else
                {
                    if (db.SysUser.Where(x => x.SuName == mo.SuName && x.SuId != mo.SuId).Count() > 0)
                    {
                        vm.Set(ARTag.exist);
                    }
                    else
                    {
                        if (mo.SuPwd != OldUserPwd)
                        {
                            mo.SuPwd = Core.CalcTo.MD5(mo.SuPwd);
                        }
                        db.SysUser.Update(mo);
                    }
                }
                int num = db.SaveChanges();

                vm.Set(num > 0);
            }

            return(vm);
        }
示例#19
0
        public string SaveCatalog(DocSetDetail mo)
        {
            var uinfo = new Func.UserAuthAid(HttpContext).Get();

            using (var db = new ContextBase())
            {
                var ds = db.DocSet.Find(mo.DsCode);
                if (ds?.Uid != uinfo.UserId)
                {
                    return("unauthorized");
                }

                mo.DsdOrder      = mo.DsdOrder ?? 99;
                mo.DsdUpdateTime = DateTime.Now;
                if (string.IsNullOrWhiteSpace(mo.DsdPid))
                {
                    mo.DsdPid = Guid.Empty.ToString();
                }

                if (string.IsNullOrWhiteSpace(mo.DsdId))
                {
                    mo.DsdId         = Guid.NewGuid().ToString();
                    mo.DsdCreateTime = mo.DsdUpdateTime;
                    mo.Uid           = uinfo.UserId;


                    db.DocSetDetail.Add(mo);
                }
                else
                {
                    var currmo = db.DocSetDetail.Where(x => x.DsdId == mo.DsdId).FirstOrDefault();
                    currmo.DsdTitle = mo.DsdTitle;
                    currmo.DsdOrder = mo.DsdOrder;
                    currmo.DsdPid   = mo.DsdPid;

                    db.DocSetDetail.Update(currmo);
                }
                int num = db.SaveChanges();

                return(num > 0 ? "success" : "fail");
            }
        }
        public void SaveChanges_GivenNewAddress_ShouldSetCreatedOnProperty()
        {
            //Arrange - Add Address
            Address address = new Address
            {
                Street     = "Test Address",
                Number     = "1",
                PostalCode = "28303",
                State      = "Bremen",
                Country    = "Germany"
            };

            ContextBase.Addresses.Add(address);

            //Act
            ContextBase.SaveChanges();

            //Assert
            Assert.True(address.CreatedOn != null);
        }
示例#21
0
        public string UpdatePassword(string oldpwd, string newpwd)
        {
            int uid = new Func.UserAuthAid(HttpContext).Get().UserId;

            using (var db = new ContextBase())
            {
                var userinfo = db.UserInfo.Find(uid);
                if (userinfo.UserPwd == Core.CalcTo.MD5(oldpwd))
                {
                    userinfo.UserPwd = Core.CalcTo.MD5(newpwd);
                    db.UserInfo.Update(userinfo);
                    var num = db.SaveChanges();
                    return(num > 0 ? "success" : "fail");
                }
                else
                {
                    return("bad");
                }
            };
        }
示例#22
0
        public string WriteDel(int id)
        {
            string result = "fail";

            int uid = new Func.UserAuthAid(HttpContext).Get().UserId;

            using (var db = new ContextBase())
            {
                var mo1 = db.UserWriting.Where(x => x.Uid == uid && x.UwId == id).FirstOrDefault();
                db.UserWriting.Remove(mo1);
                var mo2 = db.UserWritingTags.Where(x => x.UwId == id).ToList();
                db.UserWritingTags.RemoveRange(mo2);
                var mo3 = db.UserReply.Where(x => x.UrTargetId == id.ToString()).ToList();
                db.UserReply.RemoveRange(mo3);

                db.SaveChanges();
                result = "success";
            }

            return(result);
        }
        public ActionResultVM CopySysRoleAuth(SysRole mo, string copyid)
        {
            var vm = new ActionResultVM();

            using (var db = new ContextBase())
            {
                var list   = db.SysRole.Where(x => x.SrId == mo.SrId || x.SrId == copyid).ToList();
                var copymo = list.Find(x => x.SrId == copyid);
                foreach (var item in list)
                {
                    item.SrMenus   = copymo.SrMenus;
                    item.SrButtons = copymo.SrButtons;
                }
                db.SysRole.UpdateRange(list);
                int num = db.SaveChanges();

                vm.Set(num > 0);
            }

            return(vm);
        }
示例#24
0
        public IActionResult Del()
        {
            string code = RouteData.Values["id"]?.ToString();

            var uinfo = new Func.UserAuthAid(HttpContext).Get();

            using (var db = new ContextBase())
            {
                var mo = db.DocSet.Find(code);
                if (mo.Uid == uinfo.UserId)
                {
                    db.DocSet.Remove(mo);
                    var moDetail = db.DocSetDetail.Where(x => x.DsCode == code).ToList();
                    db.DocSetDetail.RemoveRange(moDetail);
                    db.SaveChanges();

                    return(Redirect("/doc/item"));
                }
            }
            return(Content("Bad"));
        }
示例#25
0
        public IActionResult RidOAuth()
        {
            if (Enum.TryParse(RouteData.Values["id"]?.ToString().ToLower(), out AccountController.ValidateloginType vtype))
            {
                int uid = new UserAuthAid(HttpContext).Get().UserId;
                using var db = new ContextBase();
                var mo = db.UserInfo.Find(uid);

                switch (vtype)
                {
                case AccountController.ValidateloginType.qq:
                    mo.OpenId1 = "";
                    break;

                case AccountController.ValidateloginType.weibo:
                    mo.OpenId2 = "";
                    break;

                case AccountController.ValidateloginType.github:
                    mo.OpenId3 = "";
                    break;

                case AccountController.ValidateloginType.taobao:
                    mo.OpenId4 = "";
                    break;

                case AccountController.ValidateloginType.microsoft:
                    mo.OpenId5 = "";
                    break;

                case AccountController.ValidateloginType.dingtalk:
                    mo.OpenId6 = "";
                    break;
                }

                db.UserInfo.Update(mo);
                db.SaveChanges();
            }
            return(Redirect("/user/setting"));
        }
示例#26
0
        public IActionResult DelMessage()
        {
            var vm = new ActionResultVM();

            var id = RouteData.Values["id"]?.ToString();

            if (!string.IsNullOrWhiteSpace(id))
            {
                var uinfo = new Func.UserAuthAid(HttpContext).Get();

                using (var db = new ContextBase())
                {
                    var um = db.UserMessage.Find(id);
                    if (um == null)
                    {
                        vm.Set(ARTag.lack);
                    }
                    else if (um?.Uid != uinfo.UserId)
                    {
                        vm.Set(ARTag.unauthorized);
                    }
                    else
                    {
                        db.UserMessage.Remove(um);
                        int num = db.SaveChanges();

                        vm.Set(num > 0);
                    }
                }
            }

            if (vm.code == 200)
            {
                return(Redirect("/user/message"));
            }
            else
            {
                return(Content(vm.ToJson()));
            }
        }
示例#27
0
        public ActionResult UpdateNewPassword(string oldpwd, string newpwd1, string newpwd2)
        {
            string result = "fail";

            if (string.IsNullOrWhiteSpace(oldpwd) || string.IsNullOrWhiteSpace(newpwd1))
            {
                result = "密码不能为空";
            }
            else if (newpwd1.Length < 5)
            {
                result = "密码长度至少 5 位";
            }
            else if (newpwd1 != newpwd2)
            {
                result = "两次输入的密码不一致";
            }
            else
            {
                var userinfo = Func.Common.GetLoginUserInfo();

                using (var db = new ContextBase())
                {
                    var mo = db.SysUser.Find(userinfo.UserId);
                    if (mo != null && mo.SuPwd == Core.CalcTo.MD5(oldpwd))
                    {
                        mo.SuPwd = Core.CalcTo.MD5(newpwd1);
                        db.SysUser.Update(mo, db);
                        db.SaveChanges();

                        result = "success";
                    }
                    else
                    {
                        result = "现有密码错误";
                    }
                }
            }

            return(Content(result));
        }
示例#28
0
        public IActionResult Message(int page = 1)
        {
            int uid = new UserAuthAid(HttpContext).Get().UserId;

            var vm = Func.Common.MessageQuery(uid, EnumAid.MessageType.UserWriting, null, page);

            vm.Route = Request.Path;

            if (page == 1)
            {
                using var db = new ContextBase();
                var listum = db.UserMessage.Where(x => x.UmType == EnumAid.MessageType.UserWriting.ToString() && x.UmAction == 2 && x.UmStatus == 1).ToList();
                if (listum.Count > 0)
                {
                    listum.ForEach(x => x.UmStatus = 2);
                    db.UserMessage.UpdateRange(listum);
                    db.SaveChanges();
                }
            }

            return(View(vm));
        }
        public ActionResultVM DelSysRole(string id)
        {
            var vm = new ActionResultVM();

            using (var db = new ContextBase())
            {
                if (db.SysUser.Where(x => x.SrId == id).Count() > 0)
                {
                    vm.Set(ARTag.exist);
                }
                else
                {
                    var mo = db.SysRole.Find(id);
                    db.SysRole.Remove(mo);
                    int num = db.SaveChanges();

                    vm.Set(num > 0);
                }
            }

            return(vm);
        }
示例#30
0
        public void GetFestivalsCollection_PageSize49_ReturnMaximum48Pages()
        {
            //Arrange - Create 49 Festivals
            ContextBase.Addresses.AddRange(
                new Address
            {
                Street     = "Test Address",
                Number     = "1",
                PostalCode = "28303",
                State      = "Bremen",
                Country    = "Germany"
            });

            ContextBase.SaveChanges();

            for (int i = 0; i < 49; i++)
            {
                ContextBase.Festivals.Add(
                    new Festival
                {
                    Title       = "Mittelalterfest 1",
                    Description = "",
                    StartDate   = DateTimeMock.Object.Now.AddDays(5),
                    EndDate     = DateTimeMock.Object.Now.AddDays(8),
                    AddressId   = ContextBase.Addresses.First(a => a.Street == "Test Address").Id
                });
            }

            ContextBase.SaveChanges();

            FestivalsResourceParametersBase.PageSize = 49;

            //Act
            var festivals = MedievalFestivalsRepositoryBase.GetFestivals(FestivalsResourceParametersBase);

            //Assert
            Assert.True(festivals.Count() == 48);
        }