/// <summary> /// This method returns an object from database as object with pagination using asynchronous operation by vmCmnParameters class as parameter. /// </summary> /// <param name="cmnParam"></param> /// <returns></returns> public async Task <object> GetPostDataWithLinq(vmCommonParam cmnParam) { List <vmPostList> listPost = null; object result = null; int recordsTotal = 0; try { using (_ctx = new FeedBackContext()) { recordsTotal = _ctx.Post.Where(x => !string.IsNullOrEmpty(cmnParam.search) ? x.PostText.Contains(cmnParam.search) : true ).Count(); listPost = await(from p in _ctx.Post where ( !string.IsNullOrEmpty(cmnParam.search) ? p.PostText.Contains(cmnParam.search) : true ) select new vmPostList { PostId = p.PostId, PostText = p.PostText, UserId = p.UserId, UserType = (_ctx.User.Where(x => x.UserId == p.UserId).FirstOrDefault().UserType), UserName = (_ctx.User.Where(x => x.UserId == p.UserId).FirstOrDefault().UserName), FullName = (_ctx.User.Where(x => x.UserId == p.UserId).FirstOrDefault().FirstName + " " + _ctx.User.Where(x => x.UserId == p.UserId).FirstOrDefault().LastName), CreationTime = p.CreationTime, TimeDiff = getTime(DateTime.Now, Convert.ToDateTime(p.CreationTime)) + " ago", RecordsTotal = recordsTotal, CommentList = ( from c in _ctx.Comment join c_u in _ctx.User on c.UserId equals c_u.UserId where c.PostId == p.PostId select new CommentList { PostId = c.PostId, CommentId = c.CommentId, CommentText = c.CommentText, CreationTime = c.CreationTime, CLike = c.CLike == null ? 0 : c.CLike, CDislike = c.CDislike == null ? 0 : c.CDislike, UserId = c.UserId, UserName = c_u.UserName, UserType = c_u.UserType, FullName = c_u.FirstName + " " + c_u.LastName, IsLikedByLoggedUser = (_ctx.OpinionLog.Where(x => x.UserId == cmnParam.UserId && x.CommentId == c.CommentId).FirstOrDefault() != null) ? (_ctx.OpinionLog.Where(x => x.UserId == cmnParam.UserId && x.CommentId == c.CommentId).FirstOrDefault().IsLike) : null } ).ToList() } ).OrderByDescending(x => x.PostId).Skip(CommonMethod.Skip(cmnParam)).Take((int)cmnParam.pageSize).ToListAsync(); } } catch (Exception ex) { } return(result = new { listPost, recordsTotal }); }
public async Task <object> CreatePost(Post model) { object result = null; string message = string.Empty; bool resstate = false; using (_ctx = new FeedBackContext()) { using (var _ctxTransaction = _ctx.Database.BeginTransaction()) { try { if (model.PostId > 0) { var objPost = await _ctx.Post.FirstOrDefaultAsync(x => x.PostId == model.PostId); objPost.PostText = model.PostText; objPost.CreationTime = DateTime.Now.ToUniversalTime(); objPost.UserId = model.UserId; } else { //var dt = DateTime.Now.ToUniversalTime(); var objPost = new Post(); objPost.PostText = model.PostText; objPost.CreationTime = DateTime.Now; objPost.UserId = model.UserId; if (objPost != null) { await _ctx.Post.AddAsync(objPost); } } await _ctx.SaveChangesAsync(); _ctxTransaction.Commit(); message = "Saved Successfully"; resstate = true; } catch (Exception ex) { _ctxTransaction.Rollback(); // Logs.WriteBug(ex); message = "Failed to save."; resstate = false; } } } return(result = new { message, resstate }); }
public async Task <object> userCreate(User model) { object result = null; string message = string.Empty; bool resstate = false; using (_ctx = new FeedBackContext()) { using (var _ctxTransaction = _ctx.Database.BeginTransaction()) { try { if (model.UserId > 0) { var objUser = await _ctx.User.FirstOrDefaultAsync(x => x.UserId == model.UserId); objUser.UserName = model.UserName; objUser.UserType = model.UserType; objUser.Password = model.Password; } else { var objUser = new User(); objUser.UserName = model.UserName; objUser.UserType = model.UserType; objUser.Password = model.Password; if (objUser != null) { await _ctx.User.AddAsync(objUser); } } await _ctx.SaveChangesAsync(); _ctxTransaction.Commit(); message = "Saved Successfully"; resstate = true; } catch (Exception ex) { _ctxTransaction.Rollback(); // Logs.WriteBug(ex); message = "Failed to save."; resstate = false; } } } return(result = new { message, resstate }); }
public async Task <object> userAuthentication(User model) { object result = null; string message = string.Empty, notificationList = string.Empty; bool resstate = false; int userId = 0; string username = ""; vmUserModel userModel = new vmUserModel(); try { using (_ctx = new FeedBackContext()) { var User = await _ctx.User.FirstOrDefaultAsync(x => (x.UserName == model.UserName || x.Email == model.UserName) && (x.Password == model.Password)); if (User != null) { userId = User.UserId; username = User.UserName; userModel.UserId = User.UserId; userModel.FirstName = User.FirstName; userModel.LastName = User.LastName; userModel.UserName = User.UserName; message = "Login Successfully."; resstate = true; } else { resstate = false; } } } catch (Exception ex) { //test } return(result = new { userModel, userId, username, message, resstate }); }
public async Task <object> userAuthentication(User model) { object result = null; string message = string.Empty, notificationList = string.Empty; bool resstate = false, isNotify = false; int noticount = 0; int userId = 0; string username = ""; try { using (_ctx = new FeedBackContext()) { var User = await _ctx.User.SingleOrDefaultAsync(x => x.UserName == model.UserName && x.Password == model.Password); if (User != null) { userId = User.UserId; username = User.UserName; message = "Login Successfully."; resstate = true; } else { resstate = false; } } } catch (Exception ex) { //test } return(result = new { userId, username, message, resstate }); }
public UserFeedBackRepository(FeedBackContext context) { _context = context; }
public async Task <object> userCreate(User model) { object result = null; string message = string.Empty; bool resstate = false; using (_ctx = new FeedBackContext()) { using (var _ctxTransaction = _ctx.Database.BeginTransaction()) { try { if (model.UserId > 0) { var objUser = await _ctx.User.FirstOrDefaultAsync(x => x.UserId == model.UserId); objUser.UserName = model.UserName; //objUser.UserType = model.UserType; objUser.Password = model.Password; objUser.FirstName = model.FirstName; objUser.LastName = model.LastName; objUser.Email = model.Email; objUser.Phone = model.Phone; objUser.UserTypeId = model.UserTypeId; objUser.Address = model.Address; objUser.BirthDate = model.BirthDate; } else { var objUser = new User(); var userId = _ctx.User.DefaultIfEmpty().Max(x => x == null ? 0 : x.UserId) + 1; var emailSplit = model.Email.Split("@"); string userName = ""; if (emailSplit != null) { userName = emailSplit[0]; } objUser.UserName = userName + "_" + userId.ToString(); //objUser.UserType = model.UserType; objUser.Password = model.Password; objUser.FirstName = model.FirstName; objUser.LastName = model.LastName; objUser.Email = model.Email; objUser.Phone = model.Phone; objUser.UserTypeId = model.UserTypeId; objUser.Address = model.Address; objUser.BirthDate = model.BirthDate; if (objUser != null) { await _ctx.User.AddAsync(objUser); } } await _ctx.SaveChangesAsync(); _ctxTransaction.Commit(); message = "Saved Successfully"; resstate = true; } catch (Exception ex) { _ctxTransaction.Rollback(); // Logs.WriteBug(ex); message = "Failed to save."; resstate = false; } } } return(result = new { message, resstate }); }
public FeedBackCommandContext(FeedBackContext context) { _context = context; }
public async Task <object> setOpinion(vmCommonParam model) { object result = null; string message = string.Empty; bool resstate = false; using (_ctx = new FeedBackContext()) { using (var _ctxTransaction = _ctx.Database.BeginTransaction()) { try { if (model.id > 0) { var objComment = await _ctx.Comment.FirstOrDefaultAsync(x => x.CommentId == model.id); var objOpinionLog = await _ctx.OpinionLog.FirstOrDefaultAsync(x => x.CommentId == model.id && x.UserId == model.UserId); if (objOpinionLog != null) { if (objOpinionLog.IsLike != model.opinion) { objComment.CDislike = !model.opinion ? (Convert.ToInt32(objComment.CDislike) + 1) : (objComment.CDislike > 0 ? (Convert.ToInt32(objComment.CDislike) - 1) : 0); objComment.CLike = model.opinion ? (Convert.ToInt32(objComment.CLike) + 1) : (objComment.CLike > 0 ? (Convert.ToInt32(objComment.CLike) - 1) : 0); } objOpinionLog.IsLike = model.opinion; } else { var opinionLog = new OpinionLog(); opinionLog.CommentId = model.id; opinionLog.UserId = model.UserId; opinionLog.IsLike = model.opinion; if (opinionLog != null) { await _ctx.OpinionLog.AddAsync(opinionLog); } objComment.CDislike = !model.opinion ? (Convert.ToInt32(objComment.CDislike) + 1) : Convert.ToInt32(objComment.CDislike); objComment.CLike = model.opinion ? (Convert.ToInt32(objComment.CLike) + 1) : Convert.ToInt32(objComment.CLike); } } await _ctx.SaveChangesAsync(); _ctxTransaction.Commit(); message = "Saved Successfully"; resstate = true; } catch (Exception ex) { _ctxTransaction.Rollback(); // Logs.WriteBug(ex); message = "Failed to save."; resstate = false; } } } return(result = new { message, resstate }); }
public FeedBackController(IUserFeedBackRepository userFeedBackRepository, FeedBackContext context) { _userFeedBackRepository = userFeedBackRepository; _context = context; }
public FeedBackContextQuery(FeedBackContext contetx) { _context = contetx; }