public async Task <bool> CreateWeightEntry(double weight, int petId)
        {
            var weightEntry = new WeightEntry
            {
                MesuredWeight = (float)weight,
                PetId         = petId,
                WeightTime    = DateTime.Now
            };

            return(await _weightEntryService.CreateWeightEntryAsync(weightEntry));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("WeightEntryId,WeightTime,MesuredWeight,PetId")] WeightEntry newWeightEntry)
        {
            if (User.Identity.IsAuthenticated)
            {
                if (ModelState.IsValid)
                {
                    newWeightEntry.WeightTime = DateTime.Now;
                    var returnValue = await _weightEntryService.CreateWeightEntryAsync(newWeightEntry);

                    if (!returnValue)
                    {
                        return(RedirectToAction("Index", "Home", new { error = true, msgToDisplay = "An error has occured with the database" }));
                    }
                    var goalReached = _weightEntryService.WeightGoalReached(newWeightEntry);
                    return(RedirectToAction("Index", "Home", new { goalReached = goalReached, goalText = "weight goal", added = true, msgToDisplay = "New weight entry has been addded!" }));
                }
                var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
                ViewBag.NoPets    = false;
                ViewData["PetId"] = await _petService.GetPetsSelectListAsync(userId);

                return(View(newWeightEntry));
            }
            return(RedirectToAction("Index", "NotAuthorized"));
        }