public async Task <IActionResult> AddFeedBack([FromBody] FeedBackDto feedBackDto) { try { var userFeedback = new UserFeedback() { FeedbackType = feedBackDto.FeedbackType, Description = feedBackDto.Description, FirstName = feedBackDto.FirstName, LastName = feedBackDto.LastName, Email = feedBackDto.Email }; await _userFeedBackRepository.AddFeedBack(userFeedback); await _context.SaveChangesAsync(); return(Ok(new { userFeedback.Id, userFeedback.FeedbackType, userFeedback.Description, userFeedback.FirstName, userFeedback.LastName, userFeedback.Email })); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task <UserFeedback> AddFeedBack(UserFeedback userFeedback) { var feedBack = await _context.UserFeedbacks.AddAsync(userFeedback); await _context.SaveChangesAsync(); return(feedBack.Entity); }
public async Task <User> Register(User user) { var userRegister = await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(userRegister.Entity); }
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> 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 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 }); }