Beispiel #1
0
        public async Task <IActionResult> Edit(int id,
                                               [Bind("WeightEntryId,WeightTime,MesuredWeight,PetId")] WeightEntry weightEntryToUpdate, int page = 1)
        {
            if (User.Identity.IsAuthenticated)
            {
                if (id != weightEntryToUpdate.WeightEntryId)
                {
                    return(NotFound());
                }
                if (ModelState.IsValid)
                {
                    var updateStatus = await _weightEntryService.UpdateWeightEntryAsync(weightEntryToUpdate);

                    if (!updateStatus)
                    {
                        return(RedirectToAction("Index", "EditEntries", new { error = true, msgToDisplay = "An error has occured with the databse." }));
                    }
                    var goalReached = _weightEntryService.WeightGoalReached(weightEntryToUpdate);
                    return(RedirectToAction("Index", "EditEntries", new { id = page, updated = true, msgToDisplay = "Weight entry has been successfully updated." }));
                }
                ViewBag.Page = page;
                return(View(weightEntryToUpdate));
            }
            return(RedirectToAction("Index", "NotAuthorized"));
        }
        public async Task <bool> UpdateWeightEntry(int entryId, double weight, int petId)
        {
            var weightEntry = _weightEntryService.GetWeightEntries().Where(e => e.WeightEntryId == entryId).First();

            weightEntry.MesuredWeight = (float)weight;
            weightEntry.PetId         = petId;
            return(await _weightEntryService.UpdateWeightEntryAsync(weightEntry));
        }