Ejemplo n.º 1
0
        protected bool crudUsersGeeltjes(Int32 geeltjeId, string noteRate, out bool isChange)
        {
            var validCount = false;

            isChange = false;
            using (var ctx = GeeltjesEntities.GetContext()) {
                try {
                    Int32 thumbUp   = 0;
                    Int32 thumbDown = 0;

                    if (noteRate == "thumbsup")
                    {
                        thumbUp = 1;
                    }
                    else
                    {
                        thumbDown = 1;
                    }

                    Icatt_Geeltjes_UserGeeltje userGeeltje =
                        ctx.Icatt_Geeltjes_UserGeeltje.FirstOrDefault(ug => ug.GeeltjeId == geeltjeId && ug.UserId == _currentUser.UserID);


                    if (userGeeltje == null)
                    {
                        //add
                        validCount  = true;
                        userGeeltje = new Icatt_Geeltjes_UserGeeltje {
                            GeeltjeId = geeltjeId,
                            UserId    = _userId,
                            ThumbDown = thumbDown,
                            ThumbUp   = thumbUp
                        };
                        // save UserGeeltje object
                        ctx.Icatt_Geeltjes_UserGeeltje.AddObject(userGeeltje);
                    }
                    else
                    {
                        if (
                            ((!userGeeltje.ThumbDown.HasValue || userGeeltje.ThumbDown.Value == 0) && thumbDown == 1) ||
                            ((!userGeeltje.ThumbUp.HasValue || userGeeltje.ThumbUp.Value == 0) && thumbUp == 1)
                            )
                        {
                            //update if count is valid
                            validCount            = true;
                            isChange              = true;
                            userGeeltje.ThumbDown = thumbDown;
                            userGeeltje.ThumbUp   = thumbUp;
                        }
                    }


                    ctx.SaveChanges();
                } catch (Exception ex) {
                    throw ex.InnerException;
                }

                return(validCount);
            }
        }
Ejemplo n.º 2
0
        protected void updatePosition(Int32 myId)
        {
            string myX = _context.Request.Params["x"];
            string myY = _context.Request.Params["y"];
            string myZ = _context.Request.Params["z"];

            if (!string.IsNullOrEmpty(myX) && !string.IsNullOrEmpty(myY) && !string.IsNullOrEmpty(myZ))
            {
                string[] myNewPos    = { myX, myY, myZ };
                String   myStrNewPos = String.Join("x", myNewPos);

                using (var ctx = GeeltjesEntities.GetContext()) {
                    try {
                        var posToUpdate = ctx.Icatt_Geeltjes_Geeltje.FirstOrDefault(geel => geel.Id == myId);
                        if (posToUpdate != null)
                        {
                            posToUpdate.Xyz = myStrNewPos;
                            ctx.SaveChanges();
                        }
                    } catch (Exception ex) {
                        throw ex.InnerException;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected void deleteNotes(Int32 geeltjeId, int moduleId)
        {
            using (var ctx = GeeltjesEntities.GetContext()) {
                try {
                    Icatt_Geeltjes_Geeltje notesToDelete;

                    notesToDelete = ctx.Icatt_Geeltjes_Geeltje.FirstOrDefault(geel => geel.Id == geeltjeId && geel.ModuleId == moduleId);


                    if (notesToDelete != null && canEditNote(notesToDelete, moduleId))
                    {
                        var userNotesToDelete = notesToDelete.Icatt_Geeltjes_UserGeeltje;

                        //Delete votes
                        foreach (var icattGeeltjesUserGeeltje in userNotesToDelete)
                        {
                            ctx.Icatt_Geeltjes_UserGeeltje.DeleteObject(icattGeeltjesUserGeeltje);
                        }

                        ctx.Icatt_Geeltjes_Geeltje.DeleteObject(notesToDelete);
                        ctx.SaveChanges();
                    }
                } catch (Exception ex) {
                    throw ex.InnerException;
                }
            }
        }
Ejemplo n.º 4
0
 protected void rateNotes(Int32 geeltjeId, string noteRate)
 {
     using (var ctx = GeeltjesEntities.GetContext()) {
         try {
             bool isChange;
             if (crudUsersGeeltjes(geeltjeId, noteRate, out isChange))
             {
                 //only allow new rating or change of rating
                 rateUpDownNotes(geeltjeId, noteRate, isChange);
             }
         } catch (Exception ex) {
             throw ex.InnerException;
         }
     }
 }
Ejemplo n.º 5
0
        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;
                }
            }
        }
Ejemplo n.º 6
0
        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);
                }
            }
        }
Ejemplo n.º 7
0
        // Override the OnLoad method to set _text to
        // a default value if it is null.
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            _settingAdapter = getModuleSettingsAdapter <Display_SettingAdapter>();

            using (var entities = GeeltjesEntities.GetContext()){
                _dataSource = entities.Icatt_Geeltjes_Geeltje
                              .Include("Icatt_Geeltjes_UserGeeltje")
                              .Where(g => g.ModuleId == this.ModuleId)
                              .ToList()
                              .Select(g => new Tuple <Icatt_Geeltjes_Geeltje, Icatt_Geeltjes_UserGeeltje>(
                                          g,
                                          g.Icatt_Geeltjes_UserGeeltje.SingleOrDefault(ug => ug.UserId == currentUser.UserID)
                                          ))
                              .ToList();
            }

            DataBind();
        }
Ejemplo n.º 8
0
        protected void updateGeeltje(Int32 myId, int moduleId)
        {
            string text  = _context.Request.Params["body"];
            string name  = _context.Request.Params["author"];
            string color = _context.Request.Params["color"];

            using (var ctx = GeeltjesEntities.GetContext()) {
                try {
                    var posToUpdate = ctx.Icatt_Geeltjes_Geeltje.FirstOrDefault(geel => geel.Id == myId && geel.ModuleId == moduleId);

                    if (posToUpdate != null && canEditNote(posToUpdate, moduleId))
                    {
                        posToUpdate.Name  = name;
                        posToUpdate.Text  = text;
                        posToUpdate.Color = color;
                        ctx.SaveChanges();
                    }
                } catch (Exception ex) {
                    throw ex.InnerException;
                }
            }
        }