public IHttpActionResult PostBoom(ViewPostVM model) { StringBuilder traceLog = null; ServiceResponse <CountVM> objResponse = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: PostBoom() Request Data:-PostId-" + model.PostId); objResponse = new ServiceResponse <CountVM>(); objResponse.jsonData = new CountVM(); objResponse.jsonData.Count = ProfileApiBL.PostBoom(model); objResponse.IsResultTrue = true; return(Ok(objResponse)); } catch (Exception ex) { LogManager.LogManagerInstance.WriteErrorLog(ex); return(BadRequest(ex.Message)); } finally { traceLog.AppendLine("End:PostBoom() Response Data:-" + objResponse.IsResultTrue + ",Posted DateTime-" + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); traceLog = null; } }
public ActionResult Index() { PostManager mgr = new PostManager(); HomeIndexVM model = new HomeIndexVM(); var allPosts = mgr.GetAllPost(); List <ViewPostVM> list = new List <ViewPostVM>(); foreach (var p in allPosts) { ViewPostVM post = new ViewPostVM() { PostTitle = p.PostTitle, PostBody = p.PostBody, PostId = p.Id, PostCategory = p.PostCategory, PostedDate = p.PostedDate, PostImageFileName = p.PostImageFileName, PostTags = p.PostTags }; list.Add(post); } model.Posts = list; return(View(model)); }
public ActionResult ViewPost(string id) { var manager = new PostManager(); var response = manager.GetById(int.Parse(id)); ViewPostVM model = new ViewPostVM() { PostBody = response.Payload.PostBody, PostCategory = response.Payload.PostCategory, PostId = response.Payload.Id, PostTitle = response.Payload.PostTitle, PostTags = response.Payload.PostTags, PostedDate = response.Payload.PostedDate, PostImageFileName = response.Payload.PostImageFileName }; return(View(model)); }
/// <summary> /// Function to post boom on challenge completed(Comment Section) /// </summary> /// <returns>int</returns> /// <devdoc> /// Developer Name - Arvind Kumar /// Date - 05/06/2015 /// </devdoc> public static int PostBoom(ViewPostVM model) { StringBuilder traceLog = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: ChallengeMessageFeedBL PostBoom"); Credentials objCred = CommonWebApiBL.GetUserId(Thread.CurrentPrincipal.Identity.Name); if (!_dbContext.Booms.Any(b => b.MessageStraemId == model.PostId && b.BoomedBy == objCred.Id)) { tblBoom objBoom = new tblBoom(); objBoom.BoomedBy = objCred.Id; objBoom.BoomedDate = DateTime.Now; objBoom.MessageStraemId = model.PostId; _dbContext.Booms.Add(objBoom); _dbContext.SaveChanges(); // Send the User Notification to user on result boomed if (model.UserId > 0 && !string.IsNullOrEmpty(model.UserType) && !(objCred.UserType == model.UserType && objCred.UserId == model.UserId)) { NotificationApiBL.SendNotificationToALLNType(model.UserId, model.UserType, NotificationType.NewsFeedBoomed.ToString(), objCred, model.PostId); } } return(_dbContext.Booms.Count(b => b.MessageStraemId == model.PostId)); } catch { throw; } finally { traceLog.AppendLine("End : ChallengeMessageFeedBL PostBoom : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to post Share message text on challenge completed(Comment Section) /// </summary> /// <returns>ViewPostVM</returns> /// <devdoc> /// Developer Name - Arvind Kumar /// Date - 05/06/2015 /// </devdoc> public static ViewPostVM PostShare(PostVM <TextMessageStream> message) { StringBuilder traceLog = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: ChallengeMessageFeedBL PostShare"); Credentials objCred = CommonWebApiBL.GetUserId(Thread.CurrentPrincipal.Identity.Name); tblMessageStream objMessageStream = new tblMessageStream(); objMessageStream.Content = message.Stream.TextMessage; objMessageStream.MessageType = Message.TextMessageType; objMessageStream.PostedDate = DateTime.Now; objMessageStream.TargetType = Message.ChallengeTargetType; objMessageStream.SubjectId = objCred.Id; objMessageStream.TargetId = message.TargetId; //ChallengeId is assigned. objMessageStream.IsTextImageVideo = true; objMessageStream.IsImageVideo = message.IsImageVideo; _dbContext.MessageStraems.Add(objMessageStream); _dbContext.SaveChanges(); if (objCred.UserType.Equals(Message.UserTypeTrainer, StringComparison.OrdinalIgnoreCase)) { // User Notification when user post message on other user or trainer post data their team member NotificationApiBL.SendALLTeamNotificationByTrainer(objCred.UserId, objMessageStream.MessageStraemId, objCred.UserId, objCred.UserType); } ViewPostVM objViewPostVM = new ViewPostVM() { PostId = objMessageStream.MessageStraemId, Message = objMessageStream.Content, PostedDate = CommonWebApiBL.GetDateTimeFormat(objMessageStream.PostedDate), BoomsCount = _dbContext.Booms.Count(b => b.MessageStraemId == objMessageStream.MessageStraemId), CommentsCount = _dbContext.Comments.Count(cmnt => cmnt.MessageStraemId == objMessageStream.MessageStraemId) }; if (objCred.UserType.Equals(Message.UserTypeUser, StringComparison.OrdinalIgnoreCase)) { var user = (from usr in _dbContext.User join crd in _dbContext.Credentials on usr.UserId equals crd.UserId where crd.UserType == Message.UserTypeUser && crd.Id == objMessageStream.SubjectId select new { usr.FirstName, usr.LastName, usr.UserImageUrl, crd.UserId, crd.UserType }).FirstOrDefault(); if (user != null) { objViewPostVM.PostedByImageUrl = string.IsNullOrEmpty(user.UserImageUrl) ? string.Empty : CommonUtility.VirtualPath + Message.ProfilePicDirectory + user.UserImageUrl; objViewPostVM.UserName = user.FirstName + " " + user.LastName; objViewPostVM.UserId = user.UserId; objViewPostVM.UserType = user.UserType; } } else if (objCred.UserType.Equals(Message.UserTypeTrainer, StringComparison.OrdinalIgnoreCase)) { var trainer = (from t in _dbContext.Trainer join crd in _dbContext.Credentials on t.TrainerId equals crd.UserId where crd.UserType == Message.UserTypeTrainer && crd.Id == objMessageStream.SubjectId select new { t.FirstName, t.LastName, t.TrainerImageUrl, crd.UserId, crd.UserType }).FirstOrDefault(); if (trainer != null) { objViewPostVM.PostedByImageUrl = string.IsNullOrEmpty(trainer.TrainerImageUrl) ? string.Empty : CommonUtility.VirtualPath + Message.ProfilePicDirectory + trainer.TrainerImageUrl; objViewPostVM.UserName = trainer.FirstName + " " + trainer.LastName; objViewPostVM.UserId = trainer.UserId; objViewPostVM.UserType = trainer.UserType; } } return(objViewPostVM); } catch { throw; } finally { traceLog.AppendLine("End:ChallengeMessageFeedBL PostShare --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }