示例#1
0
        public PastMatchLayout(PastMatch pastMatch) : base(pastMatch)
        {
            weighIns = pastMatch.WeighIns;
            WeighIn weighIn   = pastMatch.FindWeighIn();
            string  placement = pastMatch.GetPlacement(weighIn);

            this.Children.Add(new Label()
            {
                Text = placement, Style = labelStyle
            });

            if (placement != "Did Not Weigh In")
            {
                this.Children.Add(new Label()
                {
                    Text = pastMatch.GetWeight(weighIn), Style = labelStyle
                });
            }

            Button scoreboardButton = new Button {
                Text = "Scoreboard", Style = buttonStyle
            };

            this.Children.Add(scoreboardButton);
            scoreboardButton.Clicked += OnScoreboardClicked;
        }
示例#2
0
        /// <summary>
        /// Updates an existing WeighIn if it exists in the WeighIns table
        /// </summary>
        /// <param name="item"> WeighIn object to update </param>
        /// <returns> updated WeighIn object from WeighIns table </returns>
        public async Task <WeighIn> UpdateWeighInAsync(WeighIn item)
        {
            _context.WeighIns.Update(item);
            // TODO: If errors on Update, then see ProductMgmtSvc->UpdateProductAsync() for refactor

            await _context.SaveChangesAsync();

            return(await _context.WeighIns.FindAsync(item.ID));
        }
示例#3
0
        /// <summary>
        /// Creates a new Product WeighIn if a WeighIn object for same user and date doesn't already exist in the WeighIns table
        /// </summary>
        /// <param name="item"> WeighIn object to add to WeighIn table </param>
        /// <returns> WeighIn object added to WeighIns table </returns>
        public async Task <WeighIn> CreateWeighInAsync(WeighIn item)
        {
            var query = await _context.WeighIns.FirstOrDefaultAsync(w => w.UserEmail == item.UserEmail && w.Date == item.Date);

            if (query == null)
            {
                await _context.WeighIns.AddAsync(item);

                await _context.SaveChangesAsync();
            }
            return(await _context.WeighIns.FirstOrDefaultAsync(w => w.UserEmail == item.UserEmail && w.Date == item.Date));
        }
示例#4
0
        public async Task GetWeighInListAsyncTest_LiveService()
        {
            var expected = new WeighIn[1] {
                new WeighIn {
                }
            };

            var mockService = new Mock <IWeighInService>();

            mockService.Setup(w => w.GetWeighInListAsync("", 0, "")).Returns(Task.FromResult(expected));
            var service = mockService.Object;

            var repo   = new WeighInRepository(service);
            var actual = await repo.GetWeighInListAsync("", 0, "");

            Assert.AreEqual(expected.Length, actual.Length);
            Assert.AreEqual(expected[0], actual[0]);
        }
示例#5
0
        public WeighIn CreateWeighIn(string userId, decimal weight, DateTime dateRecorded)
        {
            var weighIn = db.WeighIns.FirstOrDefault(w => w.UserId == userId && w.DateRecorded.Year == dateRecorded.Year && w.DateRecorded.Month == dateRecorded.Month && w.DateRecorded.Day == dateRecorded.Day);

            if (weighIn != null)
            {
                throw new Exception("A weigh in for that date already exists.");
            }

            weighIn = new WeighIn()
            {
                UserId       = userId,
                Weight       = weight,
                DateRecorded = dateRecorded
            };

            db.WeighIns.Add(weighIn);
            db.SaveChanges();

            return(weighIn);
        }
        private async void OnWeighInClicked(object sender, EventArgs e)
        {
            string poundsString = poundsEntry.Text.Trim();
            string ouncesString = ouncesEntry.Text.Trim();

            if (poundsString.Length == 0 || ouncesString.Length == 0)
            {
                errorLabel.Text = "Both Fields Must Be Filled";
                return;
            }

            int pounds, ounces;

            if (!Int32.TryParse(poundsString, out pounds) || !Int32.TryParse(ouncesString, out ounces))
            {
                errorLabel.Text = "Invalid Entry";
                return;
            }

            if (pounds < 0 || ounces < 0 || ounces > 15)
            {
                errorLabel.Text = "Invalid Entry";
                return;
            }

            WeighIn weighIn = new WeighIn(App.User, new PoundsAndOunces(pounds, ounces));

            App.CurrentMatch.WeighIns.Add(weighIn);
            App.CurrentMatch.WeighIns.Sort(SortWeighInsByWeight);

            for (int i = 0; i < App.CurrentMatch.WeighIns.Count; i++)
            {
                App.CurrentMatch.WeighIns.ElementAt(i).Placement = i + 1;
            }

            App.SerializeCurrentMatch();
            await Navigation.PopAsync();
        }
 private static int SortWeighInsByWeight(WeighIn x, WeighIn y)
 {
     return(y.Weight.CompareTo(x.Weight));
 }