public override void Run() { using (PeContext db = new PeContext()) { for (int i = 1; i <= 10; i++) { Guid saveId = Guid.NewGuid(); string saveFile = saveId.ToString().ToUpper().Replace("-", string.Empty); Document doc = new Document() { title = "正面管教家长网络课程学习指南" + i.ToString("00"), fileName = "正面管教家长网络课程学习指南" + i.ToString("00") + ".docx", filePath = "/Document/" + saveFile, extName = "doc", fileSize = 3013678, adminId = 7, downCount = 0, createdTime = DateTime.Now, saveId = saveId, intro = "家长讲师资质课程附赠配套课件家长讲师资质课程附赠配套课件家长讲师资质课程附赠配套课家长讲师资质课程附赠配套课件家长讲师资质课程附赠配套课件家长讲师资质课程附赠配套课件家长讲师资质课程附赠配套课件家长讲师资质课程附赠配套课件", }; db.Document.Add(doc); } db.SaveChanges(); } }
private void InitCourseCategory2(PeContext context) { CourseCategoryB catB1 = new CourseCategoryB() { id = "CatB01", name = "家长课堂", weight = 1, }; CourseCategoryB catB2 = new CourseCategoryB() { id = "CatB02", name = "讲师认证家长课堂", weight = 2, }; CourseCategoryB catB3 = new CourseCategoryB() { id = "CatB03", name = "指导课家长课堂", weight = 3, }; context.CourseCategoryB.AddOrUpdate(x => x.id, catB1, catB2, catB3); context.SaveChanges(); }
public override void Run() { using (PeContext db = new PeContext()) { InitRoots(db); } }
public override void Run() { using (PeContext context = new PeContext()) { InitCourseCategory1(context); InitCourseCategory2(context); } }
protected override void Dispose(bool disposing) { if (db != null) { db.Dispose(); db = null; } base.Dispose(disposing); }
public override void Run() { using (PeContext context = new PeContext()) { AddCourse("CatA01", "CatB01", 10, context); AddCourse("CatA01", "CatB02", 7, context); AddCourse("CatA01", "CatB03", 5, context); AddCourse("CatA02", "CatB01", 3, context); AddCourse("CatA02", "CatB02", 12, context); AddCourse("CatA02", "CatB03", 6, context); } }
private void MobileLogin(OAuthGrantResourceOwnerCredentialsContext context) { AuthCustomer auth = new AuthCustomer(); using (PeContext db = new PeContext()) { var smsLogs = db.SMSLog.Where(x => x.phone == context.UserName && x.status == ConstValue.SmsStatus.Pending && x.smsType == ConstValue.SmsType.Login).OrderByDescending(x => x.createTime).ToList(); var available = smsLogs.Where(x => x.createTime >= DateTime.Now.AddMinutes(-ConstValue.SmsEffectiveTime)).FirstOrDefault(); if (available != null) { if (context.Password == available.code) { var customer = db.Customer.Where(x => x.MOBILE == context.UserName).FirstOrDefault(); if (customer == null) { Customer cus = new Customer() { MOBILE = context.UserName, CREATE_TIME = DateTime.Now, }; db.Customer.Add(cus); db.SaveChanges(); customer = db.Customer.Where(x => x.MOBILE == context.UserName).FirstOrDefault(); } customer.LAST_LOGIN_TIME = DateTime.Now; db.SaveChanges(); ClearSmsLogs(smsLogs, available, db); auth = new AuthCustomer() { CustomerId = customer.CUSTOMER_ID, Mobile = customer.MOBILE, RealName = customer.REAL_NAME, }; string json = JsonConvert.SerializeObject(auth); var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim("sub", json)); identity.AddClaim(new Claim("role", "user")); context.Validated(identity); return; } } } context.SetError("invalid_grant", "验证码不正确。"); }
private void AddCourse(string catA, string catB, int count, PeContext context) { for (int i = 1; i <= count; i++) { OnlineCourse oc = new OnlineCourse() { name = "孩子的SEL社会情感课" + i.ToString("00"), simpleIntro = "认识到人与人之间是不同的,学会在困扰之下冷静思考,并作出对自己和他人负责任的决定。", intro = "认识到人与人之间是不同的,学会在困扰之下冷静思考,并作出对自己和他人负责任的决定认识到人与人之间是不同的,学会在困扰之下冷静思考,并作出对自己和他人负责任的决定认识到人与人之间是不同的,学会在困扰之下冷静思考,并作出对自己和他人负责任的决定\r\n\r\n认识到人与人之间是不同的,学会在困扰之下冷静思考,并作出对自己和他人负责任的决定认识到人与人之间是不同的,学会在困扰之下冷静思考,并作出对自己和他人负责任的决定\r\n\r\n认识到人与人之间是不同的,学会在困扰之下冷静思考,并作出对自己和他人负责任的决定", lecturer = "简·尼尔森 & 琳·洛特", fromAge = 8, toAge = 12, price = 5800, img = "/Images/temp/kc_img.jpg", categoryA = catA, categoryB = catB, createdTime = DateTime.Now, updatedTime = DateTime.Now, publishedTime = DateTime.Now, viewCount = 10, }; oc.OnlineCourseData = new List <OnlineCourseData>(); for (int j = 1; j <= 3; j++) { OnlineCourseData item = new OnlineCourseData() { name = oc.name + "_在线课程" + j.ToString("00"), dataLink = "http://7xk2h9.com1.z0.glb.clouddn.com/no1.mp4", dataType = ConstValue.CourseDataType.Video, sort = j, }; oc.OnlineCourseData.Add(item); } OnlineCourseData tryItem = new OnlineCourseData() { name = oc.name + "_在线试看", dataLink = "http://7xlvto.media1.z0.glb.clouddn.com/PDC%E8%AE%A4%E8%AF%81%E8%AF%95%E7%9C%8B1.mp4", dataType = ConstValue.CourseDataType.TryVideo, sort = 1, }; oc.OnlineCourseData.Add(tryItem); context.OnlineCourse.Add(oc); } context.SaveChanges(); }
private void ClearSmsLogs(List <SMSLog> matchs, SMSLog available, PeContext db) { foreach (var sms in matchs) { sms.status = ConstValue.SmsStatus.Invalid; } if (available != null) { available.status = ConstValue.SmsStatus.Used; } db.SaveChanges(); }
private void InitCourseCategory1(PeContext context) { CourseCategoryA catA1 = new CourseCategoryA() { id = "CatA01", name = "全龄适用", weight = 1, }; CourseCategoryA catA2 = new CourseCategoryA() { id = "CatA02", name = "讲师认证", weight = 2, }; context.CourseCategoryA.AddOrUpdate(x => x.id, catA1, catA2); context.SaveChanges(); }
private ActionResult ProcessNotify(Pay.PayBase py, string payWay) { bool pass = py.Notify(Request); if (pass) { if (py.NotifyTradeSuccess) { using (PeContext db = new PeContext()) { var order = db.MyOrder.Where(x => x.ORDER_NUMBER == py.NotifyOutTradeNo).FirstOrDefault(); if (order != null) { if (order.PAYMWNT_STATUS == ConstValue.OrderStatus.Unpaid) { order.PAY_WAY = payWay; order.PAYMWNT_STATUS = ConstValue.OrderStatus.Paid; db.SaveChanges(); } } } } } using (PeContext db = new PeContext()) { PayNotifyLog log = new PayNotifyLog() { payWay = ConstValue.OrderPayWay.AliPay, orderNo = py.NotifyOutTradeNo, tradeNo = py.NotifyTradeNo, notifyMessage = py.NotifyMessage, notifyTime = DateTime.Now, }; db.PayNotifyLog.Add(log); db.SaveChanges(); } return(Content(py.NotifyMessage)); }
private void NormalLogin(OAuthGrantResourceOwnerCredentialsContext context) { AuthCustomer auth = new AuthCustomer(); using (PeContext db = new PeContext()) { var customer = db.Customer.Where(x => x.MOBILE == context.UserName.Trim()).FirstOrDefault(); if (customer == null) { context.SetError("invalid_grant", "用户名或密码不正确。"); return; } if (customer.USER_PASSWORD.Trim() != context.Password.Trim()) { context.SetError("invalid_grant", "用户名或密码不正确。"); return; } customer.LAST_LOGIN_TIME = DateTime.Now; db.SaveChanges(); auth = new AuthCustomer() { CustomerId = customer.CUSTOMER_ID, Mobile = customer.MOBILE, RealName = customer.REAL_NAME, }; } string json = JsonConvert.SerializeObject(auth); var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim("sub", json)); identity.AddClaim(new Claim("role", "user")); context.Validated(identity); }
private static void InitRoots(PeContext db) { ROLE_FUNCTIONS muAdmin = new ROLE_FUNCTIONS() { NAME = "账户及权限", TYPE = 0, Controller = "Admin", SORT = 1, }; db.ROLE_FUNCTIONS.Add(muAdmin); ROLE_FUNCTIONS muCustomer = new ROLE_FUNCTIONS() { NAME = "会员管理", TYPE = 0, Controller = "Customer", SORT = 2, }; db.ROLE_FUNCTIONS.Add(muCustomer); ROLE_FUNCTIONS muMainPage = new ROLE_FUNCTIONS() { NAME = "首页管理", TYPE = 0, Controller = "MainPage", SORT = 3, }; db.ROLE_FUNCTIONS.Add(muMainPage); ROLE_FUNCTIONS muCourseCategory = new ROLE_FUNCTIONS() { NAME = "课程分类", TYPE = 0, Controller = "CourseCategory", SORT = 4, }; db.ROLE_FUNCTIONS.Add(muCourseCategory); ROLE_FUNCTIONS muCourse = new ROLE_FUNCTIONS() { NAME = "线上课程", TYPE = 0, Controller = "Course", SORT = 5, }; db.ROLE_FUNCTIONS.Add(muCourse); ROLE_FUNCTIONS muQualifications = new ROLE_FUNCTIONS() { NAME = "资质管理", TYPE = 0, Controller = "Qualifications", SORT = 6, }; db.ROLE_FUNCTIONS.Add(muQualifications); ROLE_FUNCTIONS muNews = new ROLE_FUNCTIONS() { NAME = "新闻管理", TYPE = 0, Controller = "News", SORT = 7, }; db.ROLE_FUNCTIONS.Add(muNews); ROLE_FUNCTIONS muMarket = new ROLE_FUNCTIONS() { NAME = "市场合作", TYPE = 0, Controller = "Market", SORT = 8, }; db.ROLE_FUNCTIONS.Add(muMarket); ROLE_FUNCTIONS muAboutUs = new ROLE_FUNCTIONS() { NAME = "关于我们", TYPE = 0, Controller = "AboutUs", SORT = 9, }; db.ROLE_FUNCTIONS.Add(muAboutUs); ROLE_FUNCTIONS muDocument = new ROLE_FUNCTIONS() { NAME = "资料下载", TYPE = 0, Controller = "Document", SORT = 10, }; db.ROLE_FUNCTIONS.Add(muDocument); ROLE_FUNCTIONS muParentAssessment = new ROLE_FUNCTIONS() { NAME = "家长评估", TYPE = 0, Controller = "ParentAssessment", SORT = 11, }; db.ROLE_FUNCTIONS.Add(muParentAssessment); db.SaveChanges(); }
public ActionResult Login(string username, string password, string returnUrl) { using (PeContext db = new PeContext()) { var admin = db.ADMIN.Where(x => x.USER_NAME == username.Trim()).FirstOrDefault(); var a2 = db.ROLE_FUNCTION_RELATION.ToList(); var a3 = db.ROLE_FUNCTIONS.ToList(); var a4 = db.ADMIN_ROLE_RELATION.ToList(); var a = db.ADMIN.ToList(); if (admin == null) { ModelState.AddModelError("Username", "用户不存在"); ViewBag.ReturnUrl = returnUrl; return(View("Index")); } if (password.Trim() != admin.PASSWORD) { ModelState.AddModelError("Password", "密码错误"); ViewBag.ReturnUrl = returnUrl; return(View("Index")); } AuthAdmin authAdmin = new AuthAdmin() { AdminId = admin.UUID, UserName = admin.USER_NAME, RealName = admin.REAL_NAME, Mobile = admin.PHONE, }; //var a = db.ADMIN.ToList(); //var a1 = db.ADMIN_ROLE_RELATION.ToList(); //角色权限,用户与角色有对应关系 if (admin.ADMIN_ROLE_RELATION.Count > 0) { authAdmin.FirstRoleName = admin.ADMIN_ROLE_RELATION.FirstOrDefault().ROLE.NAME; } authAdmin.FunctionsId = new List <int>(); foreach (var adminRole in admin.ADMIN_ROLE_RELATION) {//查询出所有 var funs = adminRole.ROLE.ROLE_FUNCTION_RELATION.Select(x => x.FUNCTION_ID.Value).ToList(); authAdmin.FunctionsId = authAdmin.FunctionsId.Union(funs).ToList(); } //对应方法名就是权限 string json = JsonConvert.SerializeObject(authAdmin); FormsAuthentication.SetAuthCookie(json, false); } //白名单 if (!string.IsNullOrWhiteSpace(returnUrl)) { return(Redirect(returnUrl)); } else { return(Redirect(FormsAuthentication.DefaultUrl)); } }