private void Aggregate(params Type[] entitiesToAggregate_)
 {
     if (entitiesToAggregate_.FirstOrDefault(item => item == typeof(enDebate)) != null)
     {
         _enComment.Debate_ = new enDebate {
             ID = _enComment.Debate_ID
         };
         var objBLDebate = new blDebate(_enComment.Debate_);
         objBLDebate.Read();
     }
     if (entitiesToAggregate_.FirstOrDefault(item => item == typeof(enUser)) != null)
     {
         _enComment.User_ = new enUser {
             ID = _enComment.User_ID
         };
         var objBLUser = new blUser(_enComment.User_);
         objBLUser.Read();
     }
     if (entitiesToAggregate_.FirstOrDefault(item => item == typeof(enLikeCounter)) != null)
     {
         var objENLikeCounter = new enLikeCounter()
         {
             Debate_ID = _enComment.Debate_ID, User_ID = _enComment.User_ID
         };
         var objBlLikeCounter = new blLikeCounter(objENLikeCounter);
         _enComment.listOfLikeCounter = objBlLikeCounter.ReadAll().Where(x => x.Comment_ID == _enComment.ID).ToList();
         _enComment.LikesCount        = _enComment.listOfLikeCounter.Count;
     }
 }
示例#2
0
 private void ConstructObject(IDataReader dr_, enLikeCounter enLikeCounter_)
 {
     enLikeCounter_.ID         = Convert.ToInt32(dr_["ID"]);
     enLikeCounter_.Debate_ID  = Convert.ToInt32(dr_["Debate_ID"]);
     enLikeCounter_.User_ID    = Convert.ToInt32(dr_["User_ID"]);
     enLikeCounter_.Comment_ID = Convert.ToInt32(dr_["Comment_ID"]);
     enLikeCounter_.Type       = Convert.ToInt32(dr_["Type"]);
     enLikeCounter_.InsertedOn = Convert.ToDateTime(dr_["InsertedOn"]);
 }
示例#3
0
        public List <enLikeCounter> ReadAll(int?startRowIndex_ = null, int?endRowIndex_ = null)
        {
            var listOfLikeCounters = new List <enLikeCounter>();

            using (IDataReader idr = base.Read(_enLikeCounter.ID, _enLikeCounter.Debate_ID, _enLikeCounter.User_ID, _enLikeCounter.Comment_ID, startRowIndex_, endRowIndex_))
            {
                while (idr.Read())
                {
                    var objENLikeCounter = new enLikeCounter();
                    ConstructObject(idr, objENLikeCounter);
                    listOfLikeCounters.Add(objENLikeCounter);
                    _enLikeCounter.IsGetSuccess = true;
                }

                if (idr.NextResult())
                {
                    idr.Read();
                    _enLikeCounter.RecordsCount = Convert.ToInt32(idr["RecordsCount"]);
                }
            }
            return(listOfLikeCounters);
        }
示例#4
0
        public ActionResult getParticepent(int debateID)
        {
            var objENComment = new enComment()
            {
                Debate_ID = debateID
            };
            var objBLComment = new blComment(objENComment);
            List <enComment> listOfComments = new List <enComment>();

            try
            {
                listOfComments = objBLComment.ReadAllAndAggregate(null, null, typeof(enDebate), typeof(enUser));
            }
            catch
            {
                return(RedirectToAction("error", "misc"));
            }

            listOfComments = listOfComments.DistinctBy(x => x.User_ID).ToList();
            foreach (var item in listOfComments)
            {
                var objENLikeCounter = new enLikeCounter()
                {
                    User_ID = item.User_ID, Debate_ID = item.Debate_ID
                };
                var objBLLikeCounter = new blLikeCounter(objENLikeCounter);
                List <enLikeCounter> listOfLikesCounters = new List <enLikeCounter>();
                try
                {
                    listOfLikesCounters = objBLLikeCounter.ReadAll();
                    item.LikesCount     = listOfLikesCounters.Count();
                }
                catch
                {
                    return(RedirectToAction("error", "misc"));
                }
            }
            return(Json(listOfComments, JsonRequestBehavior.AllowGet));
        }
        public JsonResult DebateLike(int commentID, int userID, int debateID, int type)
        {
            var objENLikeCounter = new enLikeCounter()
            {
                Debate_ID = debateID, User_ID = userID, Comment_ID = commentID, Type = type
            };
            var objBLLikeCounter = new blLikeCounter(objENLikeCounter);

            try
            {
                objBLLikeCounter.Read();
            }
            catch (Exception ex)
            {
                Log.Error("Hangout.UI.DebateController.DebateLike() Error while Create() LikeCounter" + ex.ToString());
                return(Json("Failure", JsonRequestBehavior.AllowGet));
            }

            if (objENLikeCounter.ID == 0)
            {
                objENLikeCounter = new enLikeCounter()
                {
                    Debate_ID = debateID, User_ID = userID, Comment_ID = commentID, Type = type
                };
                objBLLikeCounter = new blLikeCounter(objENLikeCounter);
                try
                {
                    objBLLikeCounter.Create();
                }
                catch (Exception ex)
                {
                    Log.Error("Hangout.UI.DebateController.DebateLike() Error while Create() LikeCounter" + ex.ToString());
                    return(Json("Failure", JsonRequestBehavior.AllowGet));
                }
            }
            return(Json("Success", JsonRequestBehavior.AllowGet));
        }
示例#6
0
 public dlLikeCounter(enLikeCounter enLikeCounter_)
     : base("LikeCounter")
 {
     this._enLikeCounter = enLikeCounter_;
 }
 public blLikeCounter(enLikeCounter enLikeCounter_)
 {
     this._enLikeCounter = enLikeCounter_;
 }
        public ActionResult Index(int id)
        {
            #region Category
            var objENCategory = new enCategory()
            {
                ID = id
            };
            var objBLCategory = new blCategory(objENCategory);
            try
            {
                objBLCategory.Read();
            }
            catch (Exception ex)
            {
                throw;
            }
            ViewBag.Title = objENCategory.Name;
            #endregion

            var objENDebate = new enDebate()
            {
                Category_ID = id
            };
            var             objBLDebate   = new blDebate(objENDebate);
            List <enDebate> listOfDebates = new List <enDebate>();
            try
            {
                listOfDebates = objBLDebate.ReadAllAndAggregate(null, null, typeof(enUser));
            }
            catch (Exception ex)
            {
                Log.Error("Hang-Out.UI.DebateController.Index() Error while Read() Debate  Exception:- " + ex.ToString());
            }

            foreach (var item in listOfDebates)
            {
                if (item.Date.Date < DateTime.Now.Date)
                {
                    if (item.IsActive != false)
                    {
                        var objENLikeCounter = new enLikeCounter()
                        {
                            Debate_ID = item.ID
                        };
                        var objBLLikeCounter = new blLikeCounter(objENLikeCounter);
                        List <enLikeCounter> listOfLikesCounter = new List <enLikeCounter>();
                        try
                        {
                            listOfLikesCounter = objBLLikeCounter.ReadAll();
                            if (listOfLikesCounter.Count > 0)
                            {
                                var maxRepeated = listOfLikesCounter.GroupBy(s => s.User_ID).OrderByDescending(s => s.Count()).First().Key;
                                int count       = listOfLikesCounter.FindAll(x => x.User_ID == Convert.ToInt32(maxRepeated)).Count;
                                if (Convert.ToInt32(count) > 0)
                                {
                                    var objENReward = new enReward();
                                    objENReward.Point   = 50;
                                    objENReward.Type    = (int)RewardType.WINNER;
                                    objENReward.User_ID = Convert.ToInt32(maxRepeated);
                                    var objBLReward = new blReward(objENReward);
                                    try
                                    {
                                        objBLReward.Create();
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Error("Hang-Out.UI.DebateController.Index() Error while Create() Reward  Exception:-" + ex.ToString());
                                        return(RedirectToAction("error", "misc"));
                                    }

                                    item.IsActive   = false;
                                    item.LikesCount = count;
                                    item.User_ID    = maxRepeated;
                                    objBLDebate     = new blDebate(item);
                                    try
                                    {
                                        objBLDebate.Update();
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Error("Hang-Out.UI.DebateController.Index() Error while Update() Debate  Exception:-" + ex.ToString());
                                        return(RedirectToAction("error", "misc"));
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Hang-Out.UI.DebateController.Index() Error while Read() LikeCounter  Exception:-" + ex.ToString());
                            return(RedirectToAction("error", "misc"));
                        }
                    }
                }
                else if (item.Date.Date == DateTime.Now.Date)
                {
                    if (item.Start <= DateTime.Now.TimeOfDay && item.End >= DateTime.Now.TimeOfDay)
                    {
                        item.IsActive = true;
                    }
                    else if (item.Start <= DateTime.Now.TimeOfDay && item.End <= DateTime.Now.TimeOfDay)
                    {
                        if (item.IsActive != false)
                        {
                            item.IsActive = false;
                            var objENLikeCounter = new enLikeCounter()
                            {
                                Debate_ID = item.ID
                            };
                            var objBLLikeCounter = new blLikeCounter(objENLikeCounter);
                            List <enLikeCounter> listOfLikesCounter = new List <enLikeCounter>();
                            try
                            {
                                listOfLikesCounter = objBLLikeCounter.ReadAll();
                                if (listOfLikesCounter.Count > 0)
                                {
                                    var maxRepeated = listOfLikesCounter.GroupBy(s => s.User_ID).OrderByDescending(s => s.Count()).First().Key;
                                    int count       = listOfLikesCounter.FindAll(x => x.User_ID == Convert.ToInt32(maxRepeated)).Count;
                                    if (Convert.ToInt32(count) > 0)
                                    {
                                        var objENReward = new enReward();
                                        objENReward.Point   = 50;
                                        objENReward.Type    = (int)RewardType.WINNER;
                                        objENReward.User_ID = Convert.ToInt32(maxRepeated);
                                        var objBLReward = new blReward(objENReward);
                                        try
                                        {
                                            objBLReward.Create();
                                        }
                                        catch (Exception ex)
                                        {
                                            Log.Error("Hang-Out.UI.DebateController.Index() Error while Create() Reward  Exception:-" + ex.ToString());
                                            return(RedirectToAction("error", "misc"));
                                        }
                                        item.LikesCount = count;
                                        item.User_ID    = maxRepeated;
                                        objBLDebate     = new blDebate(item);
                                        try
                                        {
                                            objBLDebate.Update();
                                        }
                                        catch (Exception ex)
                                        {
                                            Log.Error("Hang-Out.UI.DebateController.Index() Error while Update() Debate  Exception:-" + ex.ToString());
                                            return(RedirectToAction("error", "misc"));
                                        }
                                    }
                                }
                                else
                                {
                                    objBLDebate = new blDebate(item);
                                    try
                                    {
                                        objBLDebate.Update();
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Error("Hangout.UI.DebateControl.Index() error while Update() Debate Exception:-" + ex.ToString());
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Log.Error("Hang-Out.UI.DebateController.Index() Error while Read() LikeCounter  Exception:-" + ex.ToString());
                                return(RedirectToAction("error", "misc"));
                            }
                        }
                    }
                    else
                    {
                        item.IsActive = false;
                    }
                }
                else
                {
                    item.IsActive = false;
                }
            }
            return(View(listOfDebates));
        }