public ActionResult PostComment(CommentInputModel comment)
        {
            if (ModelState.IsValid)
            {
                var newComment = new EventComment()
                {
                    EventId    = comment.EventId,
                    AuthorId   = this.User.Identity.GetUserId(),
                    AuthorName = this.User.Identity.GetUserName(),
                    Content    = this.Sanitizer.Sanitize(comment.Content)
                };

                this.Data.EventComments.Add(newComment);
                this.Data.SaveChanges();

                var newCommentModel = new CommentViewModel()
                {
                    Content    = this.Sanitizer.Sanitize(comment.Content),
                    AuthorName = this.User.Identity.GetUserName(),
                    CreatedOn  = newComment.CreatedOn
                };

                return(this.PartialView("_CommentPartial", newCommentModel));
            }

            return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, ModelState.Values.First().ToString()));
        }
Example #2
0
        public ActionResult Create(EventComment eventComment)
        {
            if (ModelState.IsValid)
            {
                eventComment.CommentTime = DateTime.Now;
                db.EventComments.Add(eventComment);
                db.SaveChanges();
                var evt = db.Events.Find(eventComment.EventID);
                if (evt.HostID != User.Identity.GetUserId())
                {
                    var    subject = $"Alert for {evt.Location}";
                    string Username;
                    if (User.IsInRole("GM"))
                    {
                        Username = db.GMs.Find(User.Identity.GetUserId()).Username;
                    }
                    else
                    {
                        Username = db.Players.Find(User.Identity.GetUserId()).Username;
                    }
                    var messageBody = $"{Username} commented : \n {eventComment.Comment}";
                    MessageSender.SendEmail(subject, messageBody, evt.GM.Email);
                }
                return(RedirectToAction("Details", "Events", new { id = eventComment.EventID }));
            }

            ViewBag.Event = db.Events.Find(eventComment.EventID);

            return(View(eventComment));
        }
Example #3
0
        public ActionResult Comment(long Id, string comment)
        {
            var redirector = CheckUserRights();

            if (redirector != null)
            {
                return(redirector);
            }

            try
            {
                #region
                var query  = db.Students.SingleOrDefault(x => x.PIN == "");         //Getting UserInfo
                var query1 = db.Teachers.SingleOrDefault(x => x.PIN == "");         //Getting UserInfo
                var query2 = db.Administrators.SingleOrDefault(x => x.Login == ""); //Getting UserInfo
                ViewBag.Fullname = query.FirstName + " " + query.LastName;          //Setting fullname for user
                #endregion

                EventComment c = new EventComment();
                c.EventId = Id;
                c.Date    = DateTime.Now;
                c.UserId  = query.StudentID;
                c.Text    = comment;

                db.EventComment.Add(c);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #4
0
        public IHttpActionResult PutEventComment(int id, EventComment eventComment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != eventComment.ID)
            {
                return(BadRequest());
            }

            db.Entry(eventComment).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventCommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #5
0
        public ServiceResult <EventCommentDTO[]> AddComment(int eventId, string content, HttpContext httpContext)
        {
            if (String.IsNullOrWhiteSpace(content))
            {
                return(new ServiceResult <EventCommentDTO[]>("Comment can't be empty"));
            }
            var dbEvent = _eventRepository.GetBy(e => e.Id == eventId);

            if (dbEvent == null)
            {
                return(new ServiceResult <EventCommentDTO[]>("Event doesn't exist"));
            }
            var userId = _claimsService.GetFromClaims <int?>(httpContext, ClaimTypes.Sid);

            if (userId == null)
            {
                return(new ServiceResult <EventCommentDTO[]>("UserId not found in claims"));
            }
            var newComment = new EventComment {
                EventId = eventId, UserId = (int)userId, Content = content
            };

            _eventCommentsRepository.Insert(newComment);
            return(GetEventComments(eventId));
        }
Example #6
0
        public string InsertEventComment(EventComment Info)
        {
            string Result = string.Empty;

            try
            {
                using (SqlConnection con = new SqlConnection(conn))
                {
                    SqlCommand com = new SqlCommand("SP_InsertEventComment", con);
                    com.CommandType = CommandType.StoredProcedure;
                    com.Parameters.AddWithValue("@Text", Info.Text);
                    com.Parameters.AddWithValue("@StudentID", Info.StudentID);
                    com.Parameters.AddWithValue("@TeacherID", Info.TeacherID);
                    com.Parameters.AddWithValue("@EventID", Info.EventID);
                    com.Parameters.Add("@Commentid", SqlDbType.BigInt).Direction = ParameterDirection.Output;
                    con.Open();
                    if (com.ExecuteNonQuery() > 0)
                    {
                        Result = "Success!" + com.Parameters["@Commentid"].Value.ToString();
                    }
                    else
                    {
                        Result = "Failed! ";
                    }
                    con.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return(Result);
        }
Example #7
0
        public async Task <bool> SaveComment(EventComment comment)
        {
            _context.Entry(comment).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(true);
        }
Example #8
0
        public void SendSmsNotification(int eventId)
        {
            var evt     = _db.Events.Include(e => e.Invitees).Single(e => e.EventId == eventId);
            var user    = _db.Users.Find(CurrUserId);
            var comment = new EventComment
            {
                Text       = "SMS notification send by " + user.FullName,
                SenderId   = user.UserId,
                SenderName = user.FullName,
                EventId    = eventId
            };

            _db.EventComments.Add(comment);
            _db.SaveChanges();

            var users    = _db.Users.ToList();
            var ivtIds   = evt.Invitees.Select(i => i.UserId).ToList();
            var code     = evt.GetVisibilityCode();
            var invitees = users.Where(u => ivtIds.Contains(u.UserId) || ((u.GetVisibilityCode() & code)) > 0).ToList();

            using (var srv = new SmsSrv(invitees, evt.SmsMessage))
            {
                srv.SendSMSAsync();
            }
        }
        public async Task <PartialViewResult> NewComment(string userId, int eventId, string commentMessage)
        {
            if (userId == "" || eventId == 0 || commentMessage == "")
            {
                return(null);
            }

            EventComment newEventComment = new EventComment {
                ApplicationUserId = userId,
                EventId           = eventId,
                Text                 = commentMessage,
                PublicationDate      = DateTime.Now,
                ParentEventCommentId = null
            };

            try {
                _context.EventComments.Add(newEventComment);
                await _context.SaveChangesAsync();

                var dictionay = new Dictionary <string, string>();
                dictionay.Add("Event New Comment", $"eventId: {eventId}");
                _telemetryClient.TrackEvent("UserInteraction", dictionay);
            }
            catch (Exception e) {
                _logger.LogCritical($"EXCEPCION en NewComment: {e.Message}");
                return(null);
            }

            List <EventComment> comments = await _context.EventComments
                                           .Include(c => c.ApplicationUser)
                                           .Where(c => c.EventId == eventId)
                                           .ToListAsync();

            return(PartialView("_EventComments", comments));
        }
Example #10
0
        public List <EventComment> GetEventComments(long id)
        {
            List <EventComment> Result = new List <EventComment>();

            try
            {
                using (SqlConnection con = new SqlConnection(conn))
                {
                    SqlCommand com = new SqlCommand("SP_GetAllEventCommentByEventID", con);
                    com.Parameters.AddWithValue("@EventID", id);
                    com.CommandType = CommandType.StoredProcedure;
                    con.Open();
                    SqlDataReader reader = com.ExecuteReader();
                    while (reader.Read())
                    {
                        EventComment temp = new EventComment();
                        temp.CommentID   = Convert.ToInt16(reader["ID"]);
                        temp.Text        = Convert.ToString(reader["Text"]);
                        temp.CreatedDate = Convert.ToDateTime(reader["InsertedDate"]);
                        temp.StudentName = Convert.ToString(reader["Student_Name"]);
                        temp.TeacherName = Convert.ToString(reader["TeacherName"]);
                        temp.IsStudent   = Convert.ToBoolean(reader["IsStudent"]);
                        Result.Add(temp);
                    }
                    con.Close();
                }
            }
            catch (Exception ex)
            {
                WriteLogFile.WriteErrorLog("Error.txt", ex.Message);
            }
            return(Result);
        }
Example #11
0
        public JsonResult InsertEventComment(EventComment Info)
        {
            ResultInfo <string> ResultInfo = new ResultInfo <string>()
            {
                Status      = false,
                Description = "Failed|Login"
            };

            try
            {
                if (Info != null)
                {
                    Global PageObj = new Global();
                    ResultInfo.Info = PageObj.InsertEventComment(Info);
                    if (ResultInfo.Info != null)
                    {
                        ResultInfo.Description = "Success| Insert Topic";
                        ResultInfo.Status      = true;
                    }
                }
            }
            catch (Exception ex)
            {
                ResultInfo.Description = ex.Message;
            }
            return(Json(ResultInfo, JsonRequestBehavior.AllowGet));
        }
        public async Task <IActionResult> Add([FromBody] PostEventCommentViewModel comment)
        {
            //create new comment from model
            if (!this.ModelState.IsValid)
            {
                return(NotFound());
            }

            //  var user = await this.userManager.FindByNameAsync(comment.Username);
            var @event = this.events.GetSingle(x => x.Id == comment.EventId);

            if (User == null || @event == null)
            {
                return(NotFound());
            }
            var eventComment = new EventComment()
            {
                Message = comment.Message,
                EventId = comment.EventId,
                UserId  = this.userManager.GetUserId(User),
                User    = await this.userManager.GetUserAsync(this.User)
            };

            this.comments.Add(eventComment);
            return(Ok(eventComment));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Text,PublicationDate,ApplicationUserId,EventId,ParentEventCommentId,Id")] EventComment eventComment)
        {
            if (id != eventComment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try {
                    _context.Update(eventComment);
                    await _context.SaveChangesAsync();
                } catch (DbUpdateConcurrencyException) {
                    if (!EventCommentExists(eventComment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApplicationUserId"]    = new SelectList(_context.Users, "Id", "Id", eventComment.ApplicationUserId);
            ViewData["EventId"]              = new SelectList(_context.Events, "Id", "Address", eventComment.EventId);
            ViewData["ParentEventCommentId"] = new SelectList(_context.EventComments, "Id", "ApplicationUserId", eventComment.ParentEventCommentId);
            return(View(eventComment));
        }
Example #14
0
        public ActionResult DeleteConfirmed(int id)
        {
            EventComment eventComment = db.EventComments.Find(id);

            db.EventComments.Remove(eventComment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult CreateEventComment(int eventId)
        {
            var comment = new EventComment()
            {
                EventId = eventId
            };

            return(PartialView("_CreateOrEditEventComment", comment));
        }
 public ActionResult EditEventComment(EventComment eventcomment)
 {
     if (ModelState.IsValid)
     {
         _commentRepo.InsertOrUpdateEventComments(eventcomment);
         _commentRepo.Save();
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
 }
        public ActionResult Comment(int EventID)
        {
            var          CommentList = context.PostComments.Where(x => x.EventID == EventID).ToList();
            var          Event       = context.Events.Where(x => x.EventID == EventID).FirstOrDefault();
            EventComment ec          = new EventComment();

            ec.Event        = Event;
            ec.PostComments = CommentList;
            ec.EventID      = EventID;

            return(View("Comment", ec));
        }
Example #18
0
        public IHttpActionResult PostEventComment(EventComment eventComment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.EventComments.Add(eventComment);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = eventComment.ID }, eventComment));
        }
Example #19
0
 public ActionResult Edit([Bind(Include = "EventCommentID,EventID,PlayerID,Comment,CommentTime")] EventComment eventComment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(eventComment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EventID  = new SelectList(db.Events, "EventID", "HostID", eventComment.EventID);
     ViewBag.PlayerID = new SelectList(db.Players, "PlayerID", "Username", eventComment.PlayerID);
     return(View(eventComment));
 }
Example #20
0
 public void Communicate()
 {
     if (cSocket != null)
     {
         Console.WriteLine("Начало общения...");
         EventComment?.Invoke("Начало общения...");
         while (true)
         {
             String d = ReceiveData();
             Parse(d);
         }
     }
 }
Example #21
0
 public void InsertOrUpdate(EventComment eventcomment)
 {
     if (eventcomment.Id == default(int))
     {
         // New entity
         context.EventComments.Add(eventcomment);
     }
     else
     {
         // Existing entity
         context.Entry(eventcomment).State = EntityState.Modified;
     }
 }
Example #22
0
        private void Parse(string s)
        {
            // КОМАНДА=ЗНАЧЕНИЕ (LOGIN=Иван)
            char[] sep = { '=' };
            var    cd  = s.Split(sep, 2);

            switch (cd[0])
            {
            case "LOGIN":
            {
                LoginCmdReceived?.Invoke(cd[0], cd[1]);
                break;
            }

            case "LOGIN1":
            {
                EventError?.Invoke(0);
                break;
            }

            case "MESSAGE":
            {
                MessageCmdReceived?.Invoke(cd[0], cd[1]);
                break;
            }

            case "MESSAGE1":
            {
                PrivateMessage?.Invoke(cd[0], cd[1]);
                break;
            }

            case "USERLIST":
            {
                UserListCmdReceived?.Invoke(cd[0], cd[1]);
                break;
            }

            case "START":
            {
                StartCmdReceived?.Invoke(cd[0], cd[1]);
                break;
            }

            case "ERROR":
            {
                EventComment?.Invoke("Нет пользователя");
                break;
            }
            }
        }
Example #23
0
        // GET: EventComments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EventComment eventComment = db.EventComments.Find(id);

            if (eventComment == null)
            {
                return(HttpNotFound());
            }
            return(View(eventComment));
        }
Example #24
0
        public IHttpActionResult DeleteEventComment(int id)
        {
            EventComment eventComment = db.EventComments.Find(id);

            if (eventComment == null)
            {
                return(NotFound());
            }

            db.EventComments.Remove(eventComment);
            db.SaveChanges();

            return(Ok(eventComment));
        }
        public async Task <IActionResult> Create([Bind("Text,PublicationDate,ApplicationUserId,EventId,ParentEventCommentId,Id")] EventComment eventComment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(eventComment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApplicationUserId"]    = new SelectList(_context.Users, "Id", "Id", eventComment.ApplicationUserId);
            ViewData["EventId"]              = new SelectList(_context.Events, "Id", "Address", eventComment.EventId);
            ViewData["ParentEventCommentId"] = new SelectList(_context.EventComments, "Id", "ApplicationUserId", eventComment.ParentEventCommentId);
            return(View(eventComment));
        }
Example #26
0
        public void AddComment(EventComment eventComment)
        {
            if (!_unitOfWork.EventRepository.Find(x => x.Id == eventComment.EventId).Any())
            {
                throw new Exception();
            }

            if (!_unitOfWork.UserRepository.Find(x => x.Id == eventComment.UserId).Any())
            {
                throw new Exception();
            }

            _unitOfWork.EventCommentRepository.Add(eventComment);
            _unitOfWork.SaveChanges();
        }
        public ActionResult AddComment(EventComment EC)
        {
            int           user = (int)Session["UserId"];
            PostCommentDL PC   = new PostCommentDL();
            int           id   = EC.EventID;

            PC.UserID  = user;
            PC.EventID = EC.EventID;
            PC.Comment = EC.Comment;
            PC.Name    = context.Users.Where(x => x.UserID == user).FirstOrDefault().FirstName;

            context.PostComments.Add(PC);
            context.SaveChanges();
            return(RedirectToAction("Comment", new { EventID = id }));
        }
Example #28
0
        // GET: EventComments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EventComment eventComment = db.EventComments.Find(id);

            if (eventComment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.EventID  = new SelectList(db.Events, "EventID", "HostID", eventComment.EventID);
            ViewBag.PlayerID = new SelectList(db.Players, "PlayerID", "Username", eventComment.PlayerID);
            return(View(eventComment));
        }
Example #29
0
        // GET: EventComments/Create
        public ActionResult Create(int?id)
        {
            var EventComment = new EventComment {
                EventID = id.Value
            };

            if (User.IsInRole("GM"))
            {
                EventComment.GMID = User.Identity.GetUserId();
            }
            else
            {
                EventComment.PlayerID = User.Identity.GetUserId();
            }
            ViewBag.Event = db.Events.Find(id);
            return(View(EventComment));
        }
Example #30
0
        public Event CreateOrUpdateEvent(Event info)
        {
            info.RemoveOffset();
            List <int> newUserIds = info.AcSeleUserIds;
            var        currUser   = _db.Users.Find(UserSession.CurrentUserId);

            newUserIds.Add(currUser.UserId);
            newUserIds = newUserIds.Distinct().ToList();

            info.UserGroups = info.GetVisibilityCode();

            info.CreatedUserId   = currUser.UserId;
            info.CreatedUserName = currUser.FullName;

            if (info.EventId == 0)
            {
                info.Invitees = CreateInvitees(newUserIds);
                _db.Events.Add(info);
                var comment = new EventComment
                {
                    SenderId   = currUser.UserId,
                    SenderName = currUser.FullName,
                    Text       = "Event created by " + currUser.FullName
                };
                info.Comments = new List <EventComment> {
                    comment
                };
            }
            else
            {
                UpdateInvitees(info, newUserIds);
                var comment = new EventComment
                {
                    SenderId   = currUser.UserId,
                    SenderName = currUser.FullName,
                    Text       = info.IsDeleted
                            ? "Event was cancelled by " + currUser.FullName
                            : "Event updated by " + currUser.FullName,
                    EventId = info.EventId
                };
                _db.EventComments.Add(comment);
                _db.Entry(info).State = System.Data.EntityState.Modified;
            }
            _db.SaveChanges();
            return(info);
        }
Example #31
0
 public static EventComment CreateEventComment(int eventCommentID, int eventID, int postedByUserID, bool deleted, global::System.DateTime createdDate, string createdByFullName, global::System.DateTime lastUpdatedDate, string lastUpdatedByFullName, global::System.Guid eventCommentGUID)
 {
     EventComment eventComment = new EventComment();
     eventComment.EventCommentID = eventCommentID;
     eventComment.EventID = eventID;
     eventComment.PostedByUserID = postedByUserID;
     eventComment.Deleted = deleted;
     eventComment.CreatedDate = createdDate;
     eventComment.CreatedByFullName = createdByFullName;
     eventComment.LastUpdatedDate = lastUpdatedDate;
     eventComment.LastUpdatedByFullName = lastUpdatedByFullName;
     eventComment.EventCommentGUID = eventCommentGUID;
     return eventComment;
 }
Example #32
0
 public void AddToEventComments(EventComment eventComment)
 {
     base.AddObject("EventComments", eventComment);
 }
Example #33
0
 public void Add(EventComment comment)
 {
     this.comments.Add(comment);
     this.comments.SaveChanges();
 }