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))); }
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))); }
public static InfantViewModel Create(Infant infant) { return(new InfantViewModel { Infant = infant, }); }
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)); }
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))); }
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)); }
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); }
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, }); }
public static FeedingViewModel Create(Feeding feeding, Infant infant) { return(new FeedingViewModel { Feeding = feeding, Infant = infant, }); }
public static GrowthViewModel Create(Growth growth, Infant infant) { return(new GrowthViewModel { Growth = growth, Infant = infant, }); }
public static MedicationViewModel Create(Medication medication, Infant infant) { return(new MedicationViewModel { Medication = medication, Infant = infant, }); }
public static InfantViewModel Edit(Infant infant) { return(new InfantViewModel { Infant = infant, Action = "Edit", ActionTheme = "text-white bg-yellow-500 hover:bg-yellow-600" }); }
public static InfantViewModel Details(Infant infant) { return(new InfantViewModel { Infant = infant, Action = "Details", ReadOnly = true, ShowAction = false }); }
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" }); }
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" }); }
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" }); }
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" }); }
public static DiaperViewModel Details(Diaper diaper, Infant infant) { return(new DiaperViewModel { Diaper = diaper, Infant = infant, Action = "Details", ReadOnly = true, ShowAction = false }); }
public static GrowthViewModel Details(Growth growth, Infant infant) { return(new GrowthViewModel { Growth = growth, Infant = infant, Action = "Details", ReadOnly = true, ShowAction = false }); }
public static FeedingViewModel Details(Feeding feeding, Infant infant) { return(new FeedingViewModel { Feeding = feeding, Infant = infant, Action = "Details", ReadOnly = true, ShowAction = false }); }
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" }); }
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 }); }
public static SleepViewModel Details(Sleep sleep, Infant infant) { return(new SleepViewModel { Sleep = sleep, Infant = infant, Action = "Details", ReadOnly = true, Theme = "info", ShowAction = false }); }
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 }); }
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 }); }
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 }); }
public static MedicationViewModel Details(Medication medication, Infant infant) { return(new MedicationViewModel { Medication = medication, Infant = infant, Action = "Details", ReadOnly = true, Theme = "info", ShowAction = false }); }
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 }); }
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 }); }
// 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))); }