Пример #1
0
        private async Task UpdateCardAsync(ReviewLog log, Card card, CardAction cardAction)
        {
            Task[] tasks;
            Task   logTask        = _db.InsertAsync(log);
            Task   cardUpdateTask = _db.UpdateAsync(card);

            if (cardAction == CardAction.Dismiss || cardAction == CardAction.Delete)
            {
                tasks = new[] { cardUpdateTask, logTask }
            }
            ;

            else
            {
                Task siblingsTask =
                    _db.QueryAsync <Card>(
                        @"UPDATE """ + _cardTableName + @""" SET ""Due"" = ? WHERE ""Due"" < ?"
                        + @" AND ""NoteId"" = ? AND ""Id"" <> ?",
                        DateTimeExtensions.Tomorrow.ToUnixTimestamp(),
                        DateTimeExtensions.Tomorrow.ToUnixTimestamp(), card.NoteId, card.Id);

                tasks = new[] { cardUpdateTask, logTask, siblingsTask };
            }

            await Task.WhenAll(tasks).ConfigureAwait(false);
        }
Пример #2
0
        /// <summary>Dismiss current card and fetch next one.</summary>
        /// <returns>Whether any cards are available</returns>
        /// <exception cref="System.InvalidOperationException">No card available (Current is null).</exception>
        public Task <bool> DismissAsync()
        {
            Card card = Current;

            if (card == null)
            {
                throw new InvalidOperationException("Card unavailable");
            }

            NextAction[CurrentList] = () => CurrentList.DismissAsync();
            CurrentList             = null;

            // Create review log before dismiss
            ReviewLog log = CreateLog(card);

            // Actually dismiss card
            CardAction cardAction = card.Dismiss();

            // Complete log with updated values
            CompleteLog(log, card, Grade.Dismiss);

#pragma warning disable 4014
            // Save changes to Database
            UpdateCardAsync(log, card, cardAction);
#pragma warning restore 4014

            return(DoNextAsync());
        }
Пример #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            ReviewLog reviewLog = db.ReviewLog.Find(id);

            db.ReviewLog.Remove(reviewLog);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #4
0
        // GET: ReviewLog/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ReviewLog reviewLog = db.ReviewLog.Find(id);

            if (reviewLog == null)
            {
                return(HttpNotFound());
            }
            return(View(reviewLog));
        }
Пример #5
0
        public ActionResult Edit([Bind(Include = "ReviewLogId,ASIN,WebsiteAPIId,CustomerReviewed,AutomaticValidation,AdminReviewed,DisplayReview,Rating,Email,ReviewSubject,ReviewBody,WouldBuyAgain,RecToFriend")] ReviewLog reviewLog)
        {
            if (ModelState.IsValid)
            {
                //Created new value for DateReviewed so every time user reviews
                //DateReviewed is updated to the days date while Selected date is not updated
                reviewLog.DateReviewed    = DateTime.Now.Date;
                db.Entry(reviewLog).State = EntityState.Modified;
                db.Entry(reviewLog).Property("SelectedDate").IsModified = false;



                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(reviewLog));
        }
Пример #6
0
        //
        // Internal

        private ReviewLog CreateLog(Card card)
        {
            int evalTime = Math.Min(DateTime.Now.ToUnixTimestamp() - EvalStartTime, MaxEvalTime);

            ReviewLog log = new ReviewLog(
                EvalStartTime, card.Id, card.Due, card.PracticeState, card.Interval, card.EFactor,
                evalTime);

            if (_fakeLog && LastEval > 0)
            {
                log.Id = Math.Max(LastEval + 1, EvalStartTime);
            }

            LastEval = log.Id;

            return(log);
        }
        //TODO
        /// <summary>
        /// ViewModel passed to the Index and will be utilized in CRUD functionality
        /// </summary>
        /// <param name="deal">Deal Model</param>
        /// <param name="review">Individual review records in ReviewLog Model</param>
        public ReviewLogViewModel(Deal deal, ReviewLog review)
        {
            #region Deal model

            DealID       = deal.DealID;
            ProductName  = deal.Name;
            OpenCampaign = deal.OpenCampaign;
            Category     = deal.Category;
            ImageUrl     = deal.ImageUrl;
            Description  = deal.Description;
            //RetailPrice stored as strin
            RetailPrice        = double.Parse(deal.RetailPrice);
            VendorPurchaseURL  = deal.VendorsPurchaseURL;
            OriginalPrice      = deal.OriginalPriceNumerical;
            WebsiteAPIDataId   = deal.WebsiteAPIDataId;
            ListDealFlag       = deal.ListDealFlag;
            Featured           = deal.Featured;
            CalculatedDiscount = OriginalPrice - RetailPrice;
            //VendorInfo = deal.Vendor;
            GetVendorsURL = deal.GetVendorsUrl;
            #endregion


            #region ReviewLog model

            ReviewLogId         = review.ReviewLogId;
            ASIN                = review.ASIN;
            WebsiteAPIId        = review.WebsiteAPIId;
            SelectedDate        = DateTime.Now.Date;
            CustomerReviewed    = review.CustomerReviewed;
            AutomaticValidation = review.AutomaticValidation;
            NeedsAdminReview    = review.NeedsAdminReview;
            AdminReviewed       = review.AdminReviewed;
            DisplayReview       = review.DisplayReview;
            Rating              = review.Rating;
            DateReviewed        = DateTime.Now;
            Email               = review.Email;
            ReviewSubject       = review.ReviewSubject;
            ReviewBody          = review.ReviewBody;
            WouldBuyAgain       = review.WouldBuyAgain;
            RecToFriend         = review.RecToFriend;
            #endregion
        }
Пример #8
0
        public ActionResult Create([Bind(Exclude = "Rating")] ReviewLog Review)
        {
            Random random = new Random();
            int    rDate  = random.Next(3, 30);

            rDate = (rDate * -1);
            bool[] bools = new bool[2];

            //create random bools for would buy again and refer to friend
            for (int i = 0; i < 2; i++)
            {
                bools[i] = new Random().Next(100) % 2 == 0;
            }

            int rRating = random.Next(1, 6);

            if (Review.DateReviewed == null)
            {
                Review.DateReviewed = DateTime.Now.Date;
                Review.SelectedDate = DateTime.Now.Date.AddDays(rDate); //emulate a click to get a deal 3 days ago
            }

            Review.Rating           = rRating;
            Review.ASIN             = "B01BGVLGFE";
            Review.CustomerReviewed = true;
            Review.DisplayReview    = true;
            Review.Email            = "*****@*****.**";
            Deal Deal = db.Deal.Where(db => db.ASIN == Review.ASIN).First();

            Review.WebsiteAPIId  = Deal.WebsiteAPIDataId;
            Review.WouldBuyAgain = bools[0];
            Review.RecToFriend   = bools[1];
            //TODO implement error handing
            if (ModelState.IsValid)
            {
                db.ReviewLog.Add(Review);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(Review));
        }
Пример #9
0
        public ActionResult Create([Bind(Include = "ReviewLogId,ASIN,WebsiteAPIId,SelectedDate,CustomerReviewed,AutomaticValidation,NeedsAdminReview,AdminReviewed,DisplayReview,Rating,DateReviewed,Email,ReviewSubject,ReviewBody,WouldBuyAgain,RecToFriend")] ReviewLog Review)
        {
            //Random random = new Random();
            //int rDate = random.Next(3, 30);
            //rDate = (rDate * -1);
            //bool[] bools = new bool[2];

            ////create random bools for would buy again and refer to friend
            //for (int i = 0; i < 2; i++)
            //{
            //    bools[i] = new Random().Next(100) % 2 == 0;
            //}

            //int rRating = random.Next(1, 6);
            //if (Review.DateReviewed == null)
            //{
            //    Review.DateReviewed = DateTime.Now.Date;
            //    Review.SelectedDate = DateTime.Now.Date.AddDays(rDate); //emulate a click to get a deal 3 days ago
            //}

            //Review.Rating = rRating;
            //Review.ASIN = "B01BGVLGFE";
            //Review.CustomerReviewed = true;
            //Review.DisplayReview = true;
            //Review.Email = "*****@*****.**";
            //Deal Deal = db.Deal.Where(db => db.ASIN == Review.ASIN).First();
            //Review.WebsiteAPIId = Deal.WebsiteAPIDataId;
            //Review.WouldBuyAgain = bools[0];
            //Review.RecToFriend = bools[1];
            ////TODO implement error handing
            //if (ModelState.IsValid)
            //{
            //    db.ReviewLog.Add(Review);
            //    db.SaveChanges();
            //    return RedirectToAction("Index");
            //}


            return(View(Review));
        }
Пример #10
0
        /// <summary>Answer current card and fetch next one.</summary>
        /// <param name="grade">Answer grade</param>
        /// <returns>Whether any cards are available</returns>
        /// <exception cref="System.InvalidOperationException">No card available (Current is null).</exception>
        public Task <bool> AnswerAsync(Grade grade)
        {
            // Card sanity check
            Card card = Current;

            if (card == null)
            {
                throw new InvalidOperationException("Card unavailable");
            }

            // Compute evaluation time & create review log
            ReviewLog log = CreateLog(card);

            // Answer
            NextAction[CurrentList] = () => CurrentList.MoveNextAsync();
            CurrentList             = null;

            CardAction cardAction = card.Answer(grade);

            // Complete log with updated values
            CompleteLog(log, card, grade);

            // If this was a new card, add to learning list
            if (log.LastState == PracticeState.New)
            {
                ReviewCollectionLearn.AddManual(card);
            }

#pragma warning disable 4014
            // Save changes to Database
            UpdateCardAsync(log, card, cardAction);
#pragma warning restore 4014

            ReviewCollectionNew.DismissSiblings(card);
            ReviewCollectionLearn.DismissSiblings(card);
            ReviewCollectionDue.DismissSiblings(card);

            return(DoNextAsync());
        }
Пример #11
0
        // GET: ReviewLog/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //Create the review object from id, create deal object where the ASIN/pkey matches
            ReviewLog Review = db.ReviewLog.Find(id);
            Deal      Deal   = db.Deal.Where(db => db.ASIN == Review.ASIN).First();

            //Create VM to pass to details view
            var ReviewDetailsVM = new ReviewLogViewModel(Deal, Review);


            ReviewDetailsVM.DaysSinceCodeGiven = (DateTime.Now - ReviewDetailsVM.SelectedDate);

            if (Review == null)
            {
                return(HttpNotFound());
            }
            return(View(ReviewDetailsVM));
        }
Пример #12
0
        public ActionResult CreateMock([Bind(Include = "ReviewLogId,ASIN,WebsiteAPIId,CustomerReviewed,AutomaticValidation,AdminReviewed,DisplayReview,Rating,Email,ReviewSubject,ReviewBody,WouldBuyAgain,RecToFriend")] ReviewLog reviewLog)
        {
            //TODO this is some code to generate a record automaticaly
            //List<Deal> Deals = db.Deal.ToList();
            //List<ReviewLog> Logs = db.ReviewLog.ToList();
            //ReviewLogViewModel CreateMockLog = new ReviewLogViewModel();

            //Random random = new Random();
            //int rNum = random.Next(1,6);

            //var vm = new ReviewLogViewModel(Deals.Where(d.ASIN == "B01BGVLGFE")), Logs);
            if (reviewLog.DateReviewed == null)
            {
                reviewLog.DateReviewed = DateTime.Now.Date;
                reviewLog.SelectedDate = DateTime.Now.Date.AddDays(-3); //emulate a click to get a deal 3 days ago
            }
            if (ModelState.IsValid)
            {
                db.ReviewLog.Add(reviewLog);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(reviewLog));
        }
Пример #13
0
 private void CompleteLog(ReviewLog log, Card card, Grade grade)
 {
     log.CompleteReview(
         grade, card.Due, card.PracticeState, card.Interval, card.EFactor);
 }