Exemplo n.º 1
0
        public async Task <IActionResult> Edit(long id, [FromForm] Growth growth)
        {
            if (!IsLoggedIn())
            {
                return(RedirectToPage("/Account/Login"));
            }

            Growth preSaveGrowth = await context.Growths.AsNoTracking().Include(g => g.Infant).FirstOrDefaultAsync(g => g.GrowthId == id);

            if (!IsGrowthOwner(preSaveGrowth))
            {
                return(RedirectToPage("/Error/Error404"));
            }

            Infant infant = preSaveGrowth.Infant;

            if (ModelState.IsValid)
            {
                context.Growths.Update(growth);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index", "Dashboard", new { id = growth.InfantId }));
            }
            return(View("GrowthEditor", GrowthViewModelFactory.Edit(growth, infant)));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(long id, [FromForm] Medication medication)
        {
            if (!IsLoggedIn())
            {
                return(RedirectToPage("/Account/Login"));
            }

            Medication preSaveMedication = await context.Medications.AsNoTracking().Include(m => m.Infant).FirstOrDefaultAsync(m => m.MedicationId == id);

            if (!IsMedicationOwner(preSaveMedication))
            {
                return(RedirectToPage("/Error/Error404"));
            }

            Infant infant = preSaveMedication.Infant;

            if (ModelState.IsValid)
            {
                context.Medications.Update(medication);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index", "Dashboard", new { id = medication.InfantId }));
            }
            return(View("MedicationEditor", MedicationViewModelFactory.Edit(medication, infant)));
        }
Exemplo n.º 3
0
 public static InfantViewModel Create(Infant infant)
 {
     return(new InfantViewModel
     {
         Infant = infant,
     });
 }
Exemplo n.º 4
0
        public IActionResult Index(long id)
        {
            if (!IsLoggedIn())
            {
                return(RedirectToPage("/Account/Login"));
            }
            Infant infant = context.Infants.FirstOrDefault(i => i.InfantId == id);

            if (!IsInfantOwner(infant))
            {
                return(RedirectToPage("/Error/Error404"));
            }
            IEnumerable <Diaper>     diapers     = context.Diapers.OrderByDescending(d => d.Time).Include(d => d.Infant).Where(d => d.InfantId == id);
            IEnumerable <Feeding>    feedings    = context.Feedings.OrderByDescending(f => f.StartTime).Include(f => f.Infant).Where(f => f.InfantId == id);
            IEnumerable <Growth>     growths     = context.Growths.OrderByDescending(g => g.Date).Include(g => g.Infant).Where(g => g.InfantId == id);
            IEnumerable <Medication> medications = context.Medications.OrderByDescending(m => m.Date).Include(m => m.Infant).Where(m => m.InfantId == id);
            IEnumerable <Sleep>      sleeps      = context.Sleeps.OrderByDescending(s => s.StartTime).Include(s => s.Infant).Where(s => s.InfantId == id);

            DashboardViewModel viewModel = new DashboardViewModel
            {
                Infant      = infant,
                Diapers     = diapers,
                Feedings    = feedings,
                Growths     = growths,
                Medications = medications,
                Sleeps      = sleeps
            };

            return(View("Index", viewModel));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create(long id, [FromForm] Diaper diaper)
        {
            if (!IsLoggedIn())
            {
                return(RedirectToPage("/Account/Login"));
            }

            Infant preSaveInfant = context.Infants.AsNoTracking().FirstOrDefault(i => i.InfantId == id);

            if (!IsInfantOwner(preSaveInfant))
            {
                return(RedirectToPage("/Error/Error404"));
            }

            if (ModelState.IsValid)
            {
                diaper.DiaperId = default;
                diaper.Infant   = default;
                context.Diapers.Add(diaper);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index", "Dashboard", new { id = diaper.InfantId }));
            }
            return(View("DiaperEditor", DiaperViewModelFactory.Create(diaper, preSaveInfant)));
        }
Exemplo n.º 6
0
        public ActionResult Register(Infant model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    bool jestTakaMatka = true;     //TODO warunek który nie wpuści do ifa jeśli podano nieistniejące Id
                    if (jestTakaMatka)
                    {
                        context.Infants.Add(model);
                        context.SaveChanges();
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Nie istnieje matka o podanym Id.");
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", "Rejestracja noworodka nie powiodła się.");
                }
            }

            return(View(model));
        }
Exemplo n.º 7
0
        public ActionResult Register(Infant model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    bool jestTakaMatka=true;     //TODO warunek który nie wpuści do ifa jeśli podano nieistniejące Id
                    if (jestTakaMatka)
                    {
                        context.Infants.Add(model);
                        context.SaveChanges();
                        return RedirectToAction("Index", "Home");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Nie istnieje matka o podanym Id.");
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", "Rejestracja noworodka nie powiodła się.");
                }
            }

            return View(model);
        }
Exemplo n.º 8
0
 public static SleepViewModel Create(Sleep sleep, Infant infant)
 {
     return(new SleepViewModel
     {
         Sleep = sleep,
         Infant = infant,
     });
 }
 public static DiaperViewModel Create(Diaper diaper, Infant infant)
 {
     return(new DiaperViewModel
     {
         Diaper = diaper,
         Infant = infant,
     });
 }
Exemplo n.º 10
0
 public static FeedingViewModel Create(Feeding feeding, Infant infant)
 {
     return(new FeedingViewModel
     {
         Feeding = feeding,
         Infant = infant,
     });
 }
Exemplo n.º 11
0
 public static GrowthViewModel Create(Growth growth, Infant infant)
 {
     return(new GrowthViewModel
     {
         Growth = growth,
         Infant = infant,
     });
 }
Exemplo n.º 12
0
 public static MedicationViewModel Create(Medication medication, Infant infant)
 {
     return(new MedicationViewModel
     {
         Medication = medication,
         Infant = infant,
     });
 }
Exemplo n.º 13
0
 public static InfantViewModel Edit(Infant infant)
 {
     return(new InfantViewModel
     {
         Infant = infant,
         Action = "Edit",
         ActionTheme = "text-white bg-yellow-500 hover:bg-yellow-600"
     });
 }
Exemplo n.º 14
0
 public static InfantViewModel Details(Infant infant)
 {
     return(new InfantViewModel
     {
         Infant = infant,
         Action = "Details",
         ReadOnly = true,
         ShowAction = false
     });
 }
Exemplo n.º 15
0
 public static DiaperViewModel Edit(Diaper diaper, Infant infant)
 {
     return(new DiaperViewModel
     {
         Diaper = diaper,
         Infant = infant,
         ActionTheme = "text-white bg-yellow-500 hover:bg-yellow-600",
         Action = "Edit"
     });
 }
Exemplo n.º 16
0
 public static FeedingViewModel Edit(Feeding feeding, Infant infant)
 {
     return(new FeedingViewModel
     {
         Feeding = feeding,
         Infant = infant,
         Action = "Edit",
         ActionTheme = "text-white bg-yellow-500 hover:bg-yellow-600"
     });
 }
Exemplo n.º 17
0
 public static MedicationViewModel Edit(Medication medication, Infant infant)
 {
     return(new MedicationViewModel
     {
         Medication = medication,
         Infant = infant,
         Action = "Edit",
         ActionTheme = "text-white bg-yellow-500 hover:bg-yellow-600"
     });
 }
Exemplo n.º 18
0
 public static SleepViewModel Edit(Sleep sleep, Infant infant)
 {
     return(new SleepViewModel
     {
         Sleep = sleep,
         Infant = infant,
         Action = "Edit",
         ActionTheme = "text-white bg-yellow-500 hover:bg-yellow-600"
     });
 }
Exemplo n.º 19
0
 public static DiaperViewModel Details(Diaper diaper, Infant infant)
 {
     return(new DiaperViewModel
     {
         Diaper = diaper,
         Infant = infant,
         Action = "Details",
         ReadOnly = true,
         ShowAction = false
     });
 }
Exemplo n.º 20
0
 public static GrowthViewModel Details(Growth growth, Infant infant)
 {
     return(new GrowthViewModel
     {
         Growth = growth,
         Infant = infant,
         Action = "Details",
         ReadOnly = true,
         ShowAction = false
     });
 }
Exemplo n.º 21
0
 public static FeedingViewModel Details(Feeding feeding, Infant infant)
 {
     return(new FeedingViewModel
     {
         Feeding = feeding,
         Infant = infant,
         Action = "Details",
         ReadOnly = true,
         ShowAction = false
     });
 }
Exemplo n.º 22
0
 public static GrowthViewModel Edit(Growth growth, Infant infant)
 {
     return(new GrowthViewModel
     {
         Growth = growth,
         Infant = infant,
         ActionTheme = "text-white bg-yellow-500 hover:bg-yellow-600",
         Theme = "warning",
         Action = "Edit"
     });
 }
Exemplo n.º 23
0
 public static InfantViewModel Delete(Infant infant)
 {
     return(new InfantViewModel
     {
         Infant = infant,
         Action = "Delete",
         ReadOnly = true,
         ActionTheme = "text-white bg-red-600 hover:bg-red-700",
         ShowAction = true
     });
 }
Exemplo n.º 24
0
 public static SleepViewModel Details(Sleep sleep, Infant infant)
 {
     return(new SleepViewModel
     {
         Sleep = sleep,
         Infant = infant,
         Action = "Details",
         ReadOnly = true,
         Theme = "info",
         ShowAction = false
     });
 }
Exemplo n.º 25
0
 public static GrowthViewModel Delete(Growth growth, Infant infant)
 {
     return(new GrowthViewModel
     {
         Growth = growth,
         Infant = infant,
         Action = "Delete",
         ReadOnly = true,
         ActionTheme = "text-white bg-red-600 hover:bg-red-700",
         ShowAction = true
     });
 }
Exemplo n.º 26
0
 public static MedicationViewModel Delete(Medication medication, Infant infant)
 {
     return(new MedicationViewModel
     {
         Medication = medication,
         Infant = infant,
         Action = "Delete",
         ReadOnly = true,
         ActionTheme = "text-white bg-red-600 hover:bg-red-700",
         ShowAction = true
     });
 }
Exemplo n.º 27
0
 public static FeedingViewModel Delete(Feeding feeding, Infant infant)
 {
     return(new FeedingViewModel
     {
         Feeding = feeding,
         Infant = infant,
         Action = "Delete",
         ReadOnly = true,
         ActionTheme = "text-white bg-red-600 hover:bg-red-700",
         ShowAction = true
     });
 }
Exemplo n.º 28
0
 public static MedicationViewModel Details(Medication medication, Infant infant)
 {
     return(new MedicationViewModel
     {
         Medication = medication,
         Infant = infant,
         Action = "Details",
         ReadOnly = true,
         Theme = "info",
         ShowAction = false
     });
 }
Exemplo n.º 29
0
 public static DiaperViewModel Delete(Diaper diaper, Infant infant)
 {
     return(new DiaperViewModel
     {
         Diaper = diaper,
         Infant = infant,
         Action = "Delete",
         ReadOnly = true,
         ActionTheme = "text-white bg-red-600 hover:bg-red-700",
         ShowAction = true
     });
 }
Exemplo n.º 30
0
 public static SleepViewModel Delete(Sleep sleep, Infant infant)
 {
     return(new SleepViewModel
     {
         Sleep = sleep,
         Infant = infant,
         Action = "Delete",
         ReadOnly = true,
         ActionTheme = "text-white bg-red-600 hover:bg-red-700",
         ShowAction = true
     });
 }
Exemplo n.º 31
0
        // HTTP GET
        public IActionResult Create()
        {
            if (!IsLoggedIn())
            {
                return(RedirectToPage("/Account/Login"));
            }

            Infant infant = new Infant
            {
                Dob    = DateTime.Now,
                UserId = userManager.GetUserId(User)
            };

            return(View("InfantEditor", InfantViewModelFactory.Create(infant)));
        }