public ViewResult BlogEdit(Discussion model) { if (ModelState.IsValid) { model.DiscusionType = DiscusionTypes.Blog; var updatedDisc = _srv.CreateOrUpdateDiscussion(model); } return View(model); }
public JsonResult CreateOrUpdate(Discussion model) { if (!model.AcSeleUserIds.Any() && !model.Visibilities.Any() && !model.AcCourses.Any()) { ModelState.AddModelError("", "Include at least one group or user."); } if (model.DiscussionId != 0) { var evt = _db.Discussions.Find(model.DiscussionId); var currUser = CurrentUser; if (evt.Comments[0].SenderId != currUser.UserId && !currUser.IsAdmin()) { LogUnAuth(); } } if (ModelState.IsValid) { model.DiscusionType = DiscusionTypes.Discussion; var updatedDisc = _srv.CreateOrUpdateDiscussion(model); return Json(new { url = "/Discussions/" + updatedDisc.DiscussionId }); } return GetErrorMsgJSON(); }
private void UpdateInvitees(Discussion pDisc, IEnumerable<int> newList) { var oldInvites = _db.EventInvitees.Where(e => e.EventId == pDisc.DiscussionId).ToList(); var oldIds = oldInvites.Select(i => i.UserId).ToList(); foreach (var newId in newList) { if (!oldIds.Contains(newId)) { var user = _db.Users.Find(newId); var map = new DiscussionUserMap { UserId = user.UserId, UserName = user.FullName, DiscussionId = pDisc.DiscussionId }; _db.DiscussionUserMaps.Add(map); } } foreach (var old in oldInvites) { if (!newList.Contains(old.UserId)) { _db.Entry(old).State = System.Data.EntityState.Deleted; } } pDisc.UserMap = null; }
protected List<int> GetUserIds(Discussion pDisc) { List<int> userIds = pDisc.AcSeleUserIds; foreach (var crse in pDisc.AcCourses) { userIds = userIds.Concat(GetUserFromAcCourse(crse)).ToList(); } var currUser = _db.Users.Find(UserSession.CurrentUserId); userIds.Add(currUser.UserId); userIds = userIds.Distinct().ToList(); return userIds; }
public Discussion UpdateDiscussion(Discussion pDisc) { var newIds = GetUserIds(pDisc); UpdateInvitees(pDisc, newIds); pDisc.Tags = String.Join(",", pDisc.SelectedTags) + "," + pDisc.TagCsv; pDisc.DiscussionCrowd = pDisc.GetVisibilityCode(); _db.Entry(pDisc).State = System.Data.EntityState.Modified; _db.SaveChanges(); return pDisc; }
public Discussion CreateOrUpdateDiscussion(Discussion pDisc) { if (pDisc.IsNew) { return CreateDiscussion(pDisc); } else { return UpdateDiscussion(pDisc); } }
public Discussion CreateDiscussion(Discussion pDisc) { var userIds = GetUserIds(pDisc); pDisc.UserMap = CreateUserMaps(userIds); pDisc.Tags = String.Join(",", pDisc.SelectedTags) + "," + pDisc.TagCsv; pDisc.DiscussionCrowd = pDisc.GetVisibilityCode(); pDisc.Comments = new List<DiscussionComment> { CreateComment("###Main###") }; _db.Discussions.Add(pDisc); _db.SaveChanges(); return pDisc; }