public MyAppApiResult <MemberShip> Regist(MemberShip user) { var res = new MyAppApiResult <MemberShip>(); try { using (var db = new MyAppEntities()) { #region if (db.MemberShip.Any(o => o.LoginName == user.LoginName)) { res.AddError("用户已存在"); return(res); } #endregion user.Id = Guid.NewGuid(); db.MemberShip.Add(user); db.SaveChanges(); res.Data = user; } } catch (Exception e) { res.AddError(e.Message); } return(res); }
public MyAppApiResult <bool> AddArticle(MyApp_Article article) { var result = new MyAppApiResult <bool>(); try { #region if (String.IsNullOrEmpty(article.AritcleName) || String.IsNullOrEmpty(article.SimpleText) || article.Type == null) { result.AddError("数据不全,请确认后提交"); return(result); } #endregion var db = new MyAppEntities(); article.Id = Guid.NewGuid(); article.WriteTime = DateTime.Now; article.AritcleAuthorId = Guid.NewGuid(); db.MyApp_Article.Add(article); db.SaveChanges(); } catch (Exception e) { result.AddError(e.Message); } return(result); }
public MyAppApiResult <MyApp_Article> GetArticalById(Guid Id, MemberShip CurrentUser) { var result = new MyAppApiResult <MyApp_Article>(); try { using (var db = new MyAppEntities()) { result.Data = db.MyApp_Article.FirstOrDefault(o => o.Id == Id); if (!db.MyApp_LookLog.Any(o => o.MemberShipId == CurrentUser.Id && o.ArticleId == Id)) { db.MyApp_LookLog.Add(new MyApp_LookLog() { Id = Guid.NewGuid(), MemberShipId = CurrentUser.Id, ArticleId = Id }); } db.SaveChanges(); } } catch (Exception e) { } return(result); }
public MyAppApiResult <bool> AddLog(MyApp_LookLog log) { var res = new MyAppApiResult <bool>(); try { } catch (Exception e) { res.AddError(e.Message); } return(res); }
public MyAppApiResult <MemberShip> Login(MemberShip user) { var res = new MyAppApiResult <MemberShip>(); try { using (var db = new MyAppEntities()) { var member = db.MemberShip.FirstOrDefault(o => o.LoginName == user.LoginName && o.PassWord == user.PassWord); if (member != null) { res.Data = member; } else { res.AddError("用户名或密码不正确"); return(res); } } } catch (Exception e) { res.AddError(e.Message); } return(res); }
public MyAppApiResult <bool> AddLike(Guid ArticleId, MemberShip User) { var result = new MyAppApiResult <bool>(); try { using (var db = new MyAppEntities()) { var log = db.MyApp_LookLog.FirstOrDefault(o => o.MemberShipId == User.Id && o.ArticleId == ArticleId); if (log != null) { if (log.IsLike == true) { result.AddError("已喜欢过"); return(result); } log.IsLike = true; } else { db.MyApp_LookLog.Add(new MyApp_LookLog() { Id = Guid.NewGuid(), MemberShipId = User.Id, ArticleId = ArticleId, IsLike = true }); } db.SaveChanges(); } } catch (Exception e) { result.AddError(e.Message); } return(result); }
public MyAppApiResult <bool> addFile( ) { var result = new MyAppApiResult <bool>(); return(result); }