public AccountModel GetAccount(int userId) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { WeightUser user = null; if (userId != 0) user = entity.WeightUsers.Where(e => e.UserID == userId).FirstOrDefault(); else return null; if (user != null) { AccountModel accountModel = new AccountModel(); accountModel.UserId = user.UserID; accountModel.UserName = user.UserName; accountModel.DisplayName = user.DisplayName; accountModel.StartWeight = user.StartWeight; accountModel.GoalWeight = user.GoalWeight; accountModel.EndWeight = user.EndWeight; accountModel.Paid = user.Paid; accountModel.Admin = user.Admin; return accountModel; } return null; } }
public bool DeleteCheckIn(int checkInId) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { WeightCheckIn checkIn = entity.WeightCheckIns.Where(e => e.CheckInID == checkInId).FirstOrDefault(); if (checkIn != null) { entity.DeleteObject(checkIn); int count = entity.SaveChanges(); if (count > 0) return true; } } return false; }
public bool InsertComment(CommentModel commentModel) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { WeightMsg_Comment comment = new WeightMsg_Comment(); comment.Comment_DateTime = DateTime.Now; comment.Comment_HTML = commentModel.CommentContent; comment.Post_ID = commentModel.PostId; comment.UserID = commentModel.UserId; entity.AddToWeightMsg_Comment(comment); int rows = entity.SaveChanges(); if (rows > 0) return true; else return false; } }
public PostModel GetPost(int postId) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { var post = entity.WeightMsg_Post.Include("WeightUser").Where(e => e.Post_ID == postId).FirstOrDefault(); PostModel postModel = new PostModel(); postModel.PostId = post.Post_ID; postModel.DateCreated = post.DateCreated; postModel.DateModified = post.DateModified; postModel.DisplayName = post.WeightUser.DisplayName; postModel.PostContent = post.Post_Content; postModel.Title = post.Title; postModel.UserId = post.UserID; postModel.UserName = post.WeightUser.UserName; postModel.Comments = this.GetComments(postModel.PostId); return postModel; } }
public WeightCheckInModel GetCheckInWeight(int checkInId) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { var weight = entity.WeightCheckIns.Include("WeightUser").Where(e => e.CheckInID == checkInId).FirstOrDefault(); if (weight != null) { WeightCheckInModel model = new WeightCheckInModel(); model.CheckInId = weight.CheckInID; model.UserId = weight.UserID; model.UserName = weight.WeightUser.UserName; model.Weight = weight.Weight; model.CheckInDate = weight.CheckInDate; return model; } } return null; }
public List<WeightCheckInModel> GetCheckInWeights(int userId) { List<WeightCheckInModel> weightList = new List<WeightCheckInModel>(); using (Entities entity = new Entities(BaseBISL.ConnectionString)) { var weights = entity.WeightCheckIns.Include("WeightUser").Where(e => e.UserID == userId); foreach (var weight in weights) { WeightCheckInModel model = new WeightCheckInModel(); model.CheckInId = weight.CheckInID; model.UserId = weight.UserID; model.UserName = weight.WeightUser.UserName; model.Weight = weight.Weight; model.CheckInDate = weight.CheckInDate; weightList.Add(model); } } return weightList; }
public List<CommentModel> GetComments(int postId) { List<CommentModel> commentList = new List<CommentModel>(); using (Entities entity = new Entities(BaseBISL.ConnectionString)) { var comments = entity.WeightMsg_Comment.Include("WeightMsg_Post").Include("WeightUser").Where(e => e.Post_ID == postId).OrderBy(f => f.Comment_DateTime); foreach (WeightMsg_Comment comment in comments) { CommentModel commentModel = new CommentModel(); commentModel.CommentId = comment.Comment_ID; commentModel.PostId = comment.Post_ID; commentModel.CommentDate = comment.Comment_DateTime; commentModel.DisplayName = comment.WeightUser.DisplayName; commentModel.CommentContent = comment.Comment_HTML; commentModel.UserId = comment.UserID; commentModel.UserName = comment.WeightUser.UserName; commentModel.OriginalPost = comment.WeightMsg_Post.Post_Content; commentList.Add(commentModel); } } return commentList; }
public List<PercentLostModel> GetTopStats() { List<PercentLostModel> percentList = new List<PercentLostModel>(); using (Entities entity = new Entities(BaseBISL.ConnectionString)) { var stats = entity.WeightCheckIns.Include("WeightUser").GroupBy(e => e.UserID) .Select(g => g.OrderByDescending(e => e.CheckInDate).FirstOrDefault()).ToList(); foreach (var item in stats) { if (item.WeightUser.StartWeight != null && item.WeightUser.StartWeight != 0 && item.Weight != 0 && item.WeightUser.Paid > 0) { PercentLostModel model = new PercentLostModel(); model.User = item.WeightUser.DisplayName ? item.WeightUser.UserName : item.UserID.ToString(); model.CurrentWeight = Convert.ToDecimal(item.Weight); model.StartingWeight = Convert.ToDecimal(item.WeightUser.StartWeight); percentList.Add(model); } } return percentList; } }
public List<AccountModel> GetAccounts() { List<AccountModel> accounts = new List<AccountModel>(); using (Entities entity = new Entities(BaseBISL.ConnectionString)) { var users = entity.WeightUsers.Select(e => e); foreach (WeightUser weightUser in users) { AccountModel accountModel = new AccountModel(); accountModel.Admin = weightUser.Admin; accountModel.DisplayName = weightUser.DisplayName; accountModel.EndWeight = weightUser.EndWeight; accountModel.GoalWeight = weightUser.GoalWeight; accountModel.Paid = weightUser.Paid; accountModel.StartWeight = weightUser.StartWeight; accountModel.UserId = weightUser.UserID; accountModel.UserName = weightUser.UserName; accounts.Add(accountModel); } } return accounts; }
public List<PostModel> GetPosts() { List<PostModel> postList = new List<PostModel>(); using (Entities entity = new Entities(BaseBISL.ConnectionString)) { var posts = entity.WeightMsg_Post.Include("WeightUser").Select(e => e).OrderByDescending(f => f.DateCreated); foreach (WeightMsg_Post post in posts) { PostModel postModel = new PostModel(); postModel.PostId = post.Post_ID; postModel.DateCreated = post.DateCreated; postModel.DateModified = post.DateModified; postModel.DisplayName = post.WeightUser.DisplayName; postModel.PostContent = post.Post_Content; postModel.Title = post.Title; postModel.UserId = post.UserID; postModel.UserName = post.WeightUser.UserName; postModel.Comments = this.GetComments(postModel.PostId); postList.Add(postModel); } } return postList; }
public bool UpdateAccount(AccountModel accountModel) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { WeightUser user = entity.WeightUsers.Where(e => e.UserID == accountModel.UserId).FirstOrDefault(); if (user != null) { //user.UserName = accountModel.UserName; user.DisplayName = accountModel.DisplayName; user.GoalWeight = accountModel.GoalWeight; user.StartWeight = accountModel.StartWeight; user.EndWeight = accountModel.EndWeight; user.Admin = accountModel.Admin; user.Paid = accountModel.Paid; int count = entity.SaveChanges(); if (count > 0) return true; } } return false; }
public bool RegisterAccount(RegisterModel model) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { WeightUser user = new WeightUser(); user.UserName = model.UserName; user.PW = model.Password; user.SignUpDateTime = DateTime.Now; entity.AddToWeightUsers(user); int count = entity.SaveChanges(); if (count > 0) return true; } return false; }
public bool LogOn(LogOnModel logOnModel) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { var user = entity.WeightUsers.Where (e => e.UserName == logOnModel.UserName && e.PW == logOnModel.Password).FirstOrDefault(); if (user != null) { return true; } return false; } }
public bool InsertPost(PostModel postModel) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { WeightMsg_Post post = new WeightMsg_Post(); post.DateCreated = DateTime.Now; post.DateModified = DateTime.Now; post.Post_Content = postModel.PostContent; post.Title = postModel.Title; post.UserID = postModel.UserId; entity.AddToWeightMsg_Post(post); int rows = entity.SaveChanges(); if (rows > 0) return true; else return false; } }
public bool InsertWeightCheckIn(WeightCheckInModel model) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { WeightCheckIn checkIn = new WeightCheckIn(); checkIn.UserID = model.UserId; checkIn.Weight = model.Weight; checkIn.CheckInDate = model.CheckInDate; entity.AddToWeightCheckIns(checkIn); int count = entity.SaveChanges(); if (count > 0) return true; } return false; }
public RegisterModel GetRegister(string userName) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { WeightUser user = null; if (userName != null) user = entity.WeightUsers.Where(e => e.UserName == userName).FirstOrDefault(); else return null; if (user != null) { RegisterModel register = new RegisterModel() { UserName = user.UserName }; return register; } return null; } }
public bool UpdateCheckIn(WeightCheckInModel model) { using (Entities entity = new Entities(BaseBISL.ConnectionString)) { WeightCheckIn checkIn = entity.WeightCheckIns.Where(e => e.CheckInID == model.CheckInId).FirstOrDefault(); if (checkIn != null) { //user.UserName = accountModel.UserName; checkIn.CheckInDate = model.CheckInDate; checkIn.Weight = model.Weight; int count = entity.SaveChanges(); if (count > 0) return true; } } return false; }