public async System.Threading.Tasks.Task <ActionResult> AddAsync(long?id, string ccont, long?parentId) { var result = new ResultModel(); if (id == null || id < 0) { result.Code = 1002; result.Message = " id "; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrEmpty(ccont)) { result.Code = 1002; result.Message = " ccont "; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } try { ArticleComment comment = new ArticleComment() { articleId = (long)id, contents = ccont, creatorId = long.Parse((User.Identity as ClaimsIdentity).Claims.FirstOrDefault(m => m.Type == ClaimTypes.Sid).Value), creationTime = DateTime.Now, creatorName = User.Identity.Name, imgUrl = (User.Identity as ClaimsIdentity).Claims.FirstOrDefault(m => m.Type == ClaimTypes.Uri).Value, parentId = parentId ?? 0, status = 2 }; await repository.InsertAsync(comment); var add = await repository.UnitOfWork.CommitAsync(); if (add == 1) { result.Code = 0; result.Message = string.Empty; result.Data = comment; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } else { result.Code = 1003; result.Message = "not found"; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { result.Code = 1001; result.Message = ex.Message; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> Create(PublishArticle model) { if (model == null) { ModelState.AddModelError("", "数据不允许为空!!"); } if (string.IsNullOrEmpty(model.title)) { ModelState.AddModelError("", "标题不允许为空!!"); } //if (string.IsNullOrEmpty(model.outLink)) //{ // model.outLink = "http://www.instwin.com/act/upa/content.html"; //} if (ModelState.IsValid) { var cate = new EasonRepository <ArticleCategory, long>(); var ct = await cate.GetAsync(model.categoryId); Article art = new Article() { title = model.title, contents = model.contents, creationTime = DateTime.Now, status = model.status, categoryId = model.categoryId, //channelId = model.channelId, //typeId = model.typeId, creatorName = User.Identity.Name, imageUrl = model.imageUrl, videoUrl = model.videoUrl, mTitle = model.mTitle, desc = model.desc, categoryName = ct.title, outLink = model.outLink, creatorId = long.Parse((User.Identity as ClaimsIdentity).Claims.FirstOrDefault(m => m.Type == ClaimTypes.Sid).Value) }; await repository.InsertAsync(art); await repository.UnitOfWork.CommitAsync(); return(Jsonp(new { success = true }, JsonRequestBehavior.AllowGet)); } return(View(model)); }
public async Task <ActionResult> Create(CategoryModel model) { if (ModelState.IsValid) { var category = new ArticleCategory(); category.title = model.title; category.sort = 99; category.status = 0; category.parentId = model.parentId; category.depth = model.parentId == 0 ? 0 : easonRepository.Get(model.parentId).depth + 1; category.creatorId = long.Parse((User.Identity as ClaimsIdentity).Claims.FirstOrDefault(m => m.Type == ClaimTypes.Sid).Value); category.creatorName = User.Identity.Name; category.creationTime = DateTime.Now; await easonRepository.InsertAsync(category); await easonRepository.UnitOfWork.CommitAsync(); return(RedirectToAction("Index")); } return(View(model)); }
public async System.Threading.Tasks.Task <ActionResult> Index(string phone) { var result = new ResultModel(); if (string.IsNullOrEmpty(phone)) { result.Code = 1001; result.Message = " 手机号格式不正确 "; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } if (!Utility.RegexUtils.IsPhone(phone)) { result.Code = 1002; result.Message = " 手机号格式不正确 "; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } var res = new EasonRepository <User, long>(); if (res.Count(m => m.telephone == phone) > 0) { result.Code = 1003; result.Message = " 该手机号已经注册过了 "; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } var date = DateTime.Now.AddMinutes(-1); var re = repository.FirstOrDefault(m => m.telephone == phone && m.creationTime > date); if (re != null) { result.Code = 1004; result.Message = " 请一分钟后再次发送 "; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } date = DateTime.Now.AddMinutes(60); if (repository.Count(m => m.ip == UserHostAddress && m.creationTime > date) > 1000) { result.Code = 1005; result.Message = " 该IP一小时内发送的短信数量过多"; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } IMessageService service = new MessageService(); try { var msg = new ShortMessage(); msg.creatorId = 1; msg.creatorName = "注册用户"; msg.creationTime = DateTime.Now; msg.telephone = phone; msg.code = new Random().Next(1000, 9999); msg.content = "验证码" + msg.code + ",您正在注册成为匹优爱用户,感谢您的支持!"; msg.ip = UserHostAddress; await repository.InsertAsync(msg); await repository.UnitOfWork.CommitAsync(); service.Register(msg.code.ToString(), msg.telephone); result.Code = 0; result.Message = string.Empty; result.Data = "发送成功!"; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { result.Code = 1001; result.Message = ex.Message; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } }