public IHttpActionResult AddingLike(LikeViewRequest input)
        {
            Device     device = _unitOfWork.Devices.GetSingle(x => x.DeviceToken == input.DeviceToken);
            LessonLike likes  = _unitOfWork.Likes.GetSingle(x => x.LessonId == input.LessonId && x.DeviceId == device.Id);

            if (likes == null)
            {
                var like = LessonLikeService.AddLike(input.LessonId, device.Id);
                _unitOfWork.Likes.Add(like);
                _unitOfWork.Complete();
            }

            else
            {
                if (likes.CheckLike == true)
                {
                    likes.CheckLike = false;
                }

                else if (likes.CheckLike == false)
                {
                    likes.CheckLike = true;
                }

                _unitOfWork.Complete();
            }
            return(Ok());
        }
Example #2
0
        public IHttpActionResult AddView(LikeViewRequest userInput)
        {
            Device device = _unitOfWork.Devices.GetSingle(x => x.DeviceToken == userInput.DeviceToken);

            LessonView view = _unitOfWork.Views.GetSingle(x => x.LessonId == userInput.LessonId && x.DeviceId == device.Id);

            if (view == null)
            {
                var addingView = LessonViewServices.AddView(userInput.LessonId, device.Id);
                _unitOfWork.Views.Add(addingView);
                _unitOfWork.Complete();
            }
            else
            {
                DateTime recentTime = DateTime.Now;
                DateTime lastTime   = view.LastView;

                if (recentTime.Subtract(lastTime).TotalMinutes > 120)
                {
                    view.LastView  = recentTime;
                    view.TotalView = view.TotalView + 1;

                    _unitOfWork.Complete();
                }
            }

            return(Ok());
        }
        public GeneralResponse <bool> CheckingLike(LikeViewRequest input)
        {
            Device device = _unitOfWork.Devices.GetSingle(x => x.DeviceToken == input.DeviceToken);

            if (device == null)
            {
                var result = container.Resolve <GeneralResponse <bool> >();
                result.ResponseCode    = HttpStatusCode.NotFound;
                result.ResponseMessage = "Wrong Device Token";
                result.Result          = null;

                return(result);
            }
            else
            {
                LessonLike likes = _unitOfWork.Likes.GetSingle(x => x.LessonId == input.LessonId && x.DeviceId == device.Id);
                if (likes == null)
                {
                    var checkLike = new List <bool>();
                    checkLike.Add(false);

                    var result = container.Resolve <GeneralResponse <bool> >();
                    result.ResponseCode    = HttpStatusCode.OK;
                    result.ResponseMessage = "Request is okay";
                    result.Result          = checkLike;

                    return(result);
                }

                else
                {
                    var checkLike = new List <bool>();
                    checkLike.Add(likes.CheckLike);

                    var result = container.Resolve <GeneralResponse <bool> >();
                    result.ResponseCode    = HttpStatusCode.OK;
                    result.ResponseMessage = "Request is okay";
                    result.Result          = checkLike;

                    return(result);
                }
            }
        }