private bool canEditNote(Icatt_Geeltjes_Geeltje geeltje, int moduleId) { if (geeltje.CreatedByUserId == _currentUser.UserID) { return(true); } var mc = new ModuleController(); var modInfo = mc.GetModule(moduleId); return(ModulePermissionController.CanEditModuleContent(modInfo)); }
protected int addGeeltje() { using (var ctx = GeeltjesEntities.GetContext()) { try { string myUserName = _context.Request.Params["author"]; string myText = _context.Request.Params["body"]; string myColor = _context.Request.Params["color"]; string moduleIdValue = _context.Request.Params["moduleId"]; string myX = _context.Request.Params["x"]; string myY = _context.Request.Params["y"]; string myZ = _context.Request.Params["zIndex"]; string[] myNewPos = { myX, myY, myZ }; String myStrNewPos = String.Join("x", myNewPos); int moduleId = -1; if (!int.TryParse(moduleIdValue, out moduleId)) { throw new ArgumentException("Missing or invalid 'moduleId' parameter in request to add geeltje for AjaxHandler"); } var newNotes = new Icatt_Geeltjes_Geeltje { Color = myColor , Name = myUserName , Text = myText , Xyz = myStrNewPos , CreatedAt = DateTime.Now , CreatedByUserId = _userId , ModuleId = moduleId }; ctx.Icatt_Geeltjes_Geeltje.AddObject(newNotes); ctx.SaveChanges(); return(newNotes.Id); } catch (Exception ex) { throw ex.InnerException; } } }
protected void rateUpDownNotes(Int32 geeltjeId, string noteRate, bool isChange) { using (var ctx = GeeltjesEntities.GetContext()) { try { Icatt_Geeltjes_Geeltje notesToRate = ctx.Icatt_Geeltjes_Geeltje.FirstOrDefault(geel => geel.Id == geeltjeId); if (notesToRate != null) { Int32 noteThumbUpCount = notesToRate.ThumbUpCount.HasValue ? notesToRate.ThumbUpCount.Value : 0; Int32 noteThumbDownCount = notesToRate.ThumbDownCount.HasValue ? notesToRate.ThumbDownCount.Value : 0; if (noteRate == "thumbsup") { //increase 1 the ThumbUpCount of the notes noteThumbUpCount++; notesToRate.ThumbUpCount = noteThumbUpCount; if (isChange) { //change of thumbs down to thumbs up. decrease thumb down noteThumbDownCount--; notesToRate.ThumbDownCount = noteThumbDownCount; } } else { //increase 1 the ThumbDownCount of the notes noteThumbDownCount++; notesToRate.ThumbDownCount = noteThumbDownCount; if (isChange) { //change of thumbsup to thubsdown. decrease thumb up noteThumbUpCount--; notesToRate.ThumbUpCount = noteThumbUpCount; } } // save Geeltje object ctx.SaveChanges(); } } catch (Exception ex) { throw new InvalidOperationException(string.Format("There was an error rating this notes : {0}", ex.Message), ex); } } }