コード例 #1
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());
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        public GeneralResponse <Device> AddDeivce(Device device)
        {
            var result = container.Resolve <GeneralResponse <Device> >();

            if (!ModelState.IsValid)
            {
                result.ResponseCode    = HttpStatusCode.BadRequest;
                result.ResponseMessage = "Invalid Request";
                result.Result          = null;
                return(result);
            }

            var dev = _unitOfWork.Devices.GetSingle(x => x.DeviceToken == device.DeviceToken);

            if (dev == null)
            {
                _unitOfWork.Devices.Add(dev);
                _unitOfWork.Complete();

                result.ResponseCode    = HttpStatusCode.OK;
                result.ResponseMessage = "Request is okay";
                result.Result          = (IEnumerable <Device>)_unitOfWork.Devices.GetByID(dev.Id);
                return(result);
            }
            else
            {
                result.ResponseCode    = HttpStatusCode.Conflict;
                result.ResponseMessage = "This device has been already registered";
                result.Result          = (IEnumerable <Device>)_unitOfWork.Devices.GetByID(dev.Id);
                return(result);
            }
        }