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)));
        }
Beispiel #2
0
        public Diaper UpdateDiaper(Diaper diaper, int careTakerId)
        {
            using (SqlConnection conn = new SqlConnection(this.connectionString))
            {
                conn.Open();

                const string sql = @"UPDATE diaper
                                        SET diaper.time = @time,
                                        diaper.notes = @notes
                                        OUTPUT INSERTED.diaper_id
                                        FROM diaper
                                        JOIN session ON diaper.session_id = session.session_id
                                        JOIN session_caretaker ON session.session_id = session_caretaker.session_id
                                        WHERE diaper.diaper_id = @diaper_id
                                        AND session_caretaker.caretaker_id = @caretaker_id";

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@time", diaper.Time);
                cmd.Parameters.AddWithValue("@notes", diaper.Notes);
                cmd.Parameters.AddWithValue("@diaper_id", diaper.DiaperId);
                cmd.Parameters.AddWithValue("@caretaker_id", careTakerId);

                diaper.DiaperId = Convert.ToInt32(cmd.ExecuteScalar());

                return(diaper);
            }
        }
Beispiel #3
0
        public Diaper GetADiaperBySession(int sessionId, int careTakerId, int diaperId)
        {
            Diaper diaper = new Diaper();

            using (SqlConnection conn = new SqlConnection(this.connectionString))
            {
                conn.Open();

                const string sql = @"SELECT *
                                        FROM diaper
                                        JOIN session ON diaper.session_id = session.session_id
                                        JOIN session_caretaker ON session.session_id = session_caretaker.session_id
                                        WHERE diaper.session_id = @session_id
                                        AND diaper.diaper_id = @diaper_id
                                        AND session_caretaker.caretaker_id = @caretaker_id";

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@session_id", sessionId);
                cmd.Parameters.AddWithValue("@caretaker_id", careTakerId);
                cmd.Parameters.AddWithValue("@diaper_id", diaperId);

                SqlDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    diaper = ParseRow(rdr);
                }

                return(diaper);
            }
        }
Beispiel #4
0
        public async Task <IActionResult> OnPostNewDiaperAsync(int id)
        {
            ModelState.Remove("Document");
            if (ModelState.IsValid)
            {
                ApplicationUser UpUser = await UserManager.FindByIdAsync(UserManager.GetUserId(User));

                var student = await Context.Student.FirstOrDefaultAsync(
                    m => m.StudentId == id);

                var diaper = new Diaper
                {
                    Time    = Diaper.Time,
                    Wet     = Diaper.Wet,
                    Dirty   = Diaper.Dirty,
                    Note    = Diaper.Note,
                    Changer = UpUser,
                    Student = student
                };



                Context.Add(diaper);
                await Context.SaveChangesAsync();

                return(RedirectToPage("./Details", new { id }));
            }
            return(RedirectToPage("./Details", new { id }));
        }
 public static DiaperViewModel Create(Diaper diaper, Infant infant)
 {
     return(new DiaperViewModel
     {
         Diaper = diaper,
         Infant = infant,
     });
 }
 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 DiaperViewModel Details(Diaper diaper, Infant infant)
 {
     return(new DiaperViewModel
     {
         Diaper = diaper,
         Infant = infant,
         Action = "Details",
         ReadOnly = true,
         ShowAction = false
     });
 }
Beispiel #8
0
        public ActionResult AddDiapers(int numberOfDiapers, string dateUsed)
        {
            //convert date
            DateTime oDate = DateTime.ParseExact(dateUsed, "dd/MM/yyyy HH:mm", null);

            Diaper diaper = new Diaper(numberOfDiapers, oDate);

            db.Diapers.Add(diaper);
            db.SaveChanges();
            return(View("Diaper", db.Diapers.ToList().OrderByDescending(x => x.Date_Used)));
        }
Beispiel #9
0
        public void TestGetADiaperBySession()
        {
            // Arrange
            DiaperSqlDAO dao = new DiaperSqlDAO(this.connectionString);

            // Act
            Diaper diaper = dao.GetADiaperBySession(session1, ruth, diaper1);

            // Assert
            Assert.AreEqual("Nothing Unusal", diaper.Notes);
        }
        // GET: Diapers/Create
        public async Task <IActionResult> Create(Guid Id)
        {
            ViewData["Teacher"] = new SelectList(_context.Teachers, "Id", "FirstName");
            Diaper diaper = new Diaper();

            diaper.Child_Id = Id;
            var child = await _context.Children.FirstOrDefaultAsync(m => m.Id == Id);

            diaper.ChildName = child.FirstName + " " + child.LastName;
            return(View(diaper));
        }
 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
     });
 }
Beispiel #12
0
        public ActionResult <Nap> UpdateDiaper(int sessionId, int diaperId, Diaper diaper)
        {
            Session checkSession = sessionDao.GetSessionById(sessionId, userId);

            if (checkSession.SessionId == 0)
            {
                return(NotFound());
            }

            diaper.DiaperId = diaperId;
            Diaper updatedDiaper = diaperDao.UpdateDiaper(diaper, userId);

            return(Created($"/api/sessions/{sessionId}/naps/{updatedDiaper.DiaperId}", updatedDiaper));
        }
Beispiel #13
0
        public ActionResult <Nap> CreateDiaper(Diaper diaper, int sessionId)
        {
            Session session = sessionDao.GetSessionById(sessionId, userId);

            if (session.SessionId == 0)
            {
                return(NotFound());
            }

            diaper.SessionId = sessionId;
            Diaper newMeal = diaperDao.AddDiaper(diaper);

            return(Created($"/api/sessions/{sessionId}/naps/{newMeal.DiaperId}", newMeal));
        }
Beispiel #14
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Diaper = await _context.Diapers.FirstOrDefaultAsync(m => m.id == id);

            if (Diaper == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        // HTTP GEt
        public async Task <IActionResult> Delete(long id)
        {
            if (!IsLoggedIn())
            {
                return(RedirectToPage("/Account/Login"));
            }

            Diaper diaper = await context.Diapers.Include(f => f.Infant).FirstOrDefaultAsync(f => f.DiaperId == id);

            if (!IsDiaperOwner(diaper))
            {
                return(RedirectToPage("/Error/Error404"));
            }

            return(View("DiaperEditor", DiaperViewModelFactory.Delete(diaper, diaper.Infant)));
        }
Beispiel #16
0
        public void TestAddDiaper()
        {
            // Arrange
            DiaperSqlDAO dao       = new DiaperSqlDAO(this.connectionString);
            Diaper       newDiaper = new Diaper()
            {
                SessionId = session1,
                Time      = DateTime.Now,
                Notes     = "Was Fussy"
            };

            // Act
            Diaper diaper = dao.AddDiaper(newDiaper);

            // Assert
            Assert.AreEqual(newDiaper.Notes, diaper.Notes);
        }
Beispiel #17
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Diaper = await _context.Diapers.FindAsync(id);

            if (Diaper != null)
            {
                _context.Diapers.Remove(Diaper);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Beispiel #18
0
        public ActionResult <Diaper> GetDiaperById(int sessionId, int diaperId)
        {
            Session session = sessionDao.GetSessionById(sessionId, userId);

            if (session.SessionId == 0)
            {
                return(NotFound());
            }

            Diaper diaper = diaperDao.GetADiaperBySession(sessionId, userId, diaperId);

            if (diaper.DiaperId == 0)
            {
                return(NotFound());
            }

            return(Ok(diaper));
        }
Beispiel #19
0
        public bool CreateDiaper(DiaperCreate model)
        {
            var entity =
                new Diaper()
            {
                ParentID = _userID,
                BabyID   = model.BabyID,
                Soiled   = model.Soiled,
                Time     = model.Time,
                Notes    = model.Notes
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Diapers.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Beispiel #20
0
        private Diaper ParseRow(SqlDataReader rdr)
        {
            Diaper diaper = new Diaper();

            diaper.DiaperId  = Convert.ToInt32(rdr["diaper_id"]);
            diaper.SessionId = Convert.ToInt32(rdr["session_id"]);

            if (rdr["time"] != DBNull.Value)
            {
                diaper.Time = Convert.ToDateTime(rdr["time"]);
            }

            if (rdr["notes"] != DBNull.Value)
            {
                diaper.Notes = Convert.ToString(rdr["notes"]);
            }

            return(diaper);
        }
Beispiel #21
0
        public Diaper AddDiaper(Diaper diaper)
        {
            using (SqlConnection conn = new SqlConnection(this.connectionString))
            {
                conn.Open();

                const string sql = @"INSERT INTO diaper (session_id, time, notes)
	                                    VALUES (@session_id, @time, @notes)
                                        SELECT @@IDENTITY";

                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@session_id", diaper.SessionId);
                cmd.Parameters.AddWithValue("@time", diaper.Time);
                cmd.Parameters.AddWithValue("@notes", diaper.Notes);

                diaper.DiaperId = Convert.ToInt32(cmd.ExecuteScalar());

                return(diaper);
            }
        }
        // HTTP Get
        public IActionResult Create(long id)
        {
            if (!IsLoggedIn())
            {
                return(RedirectToPage("/Account/Login"));
            }
            Infant infant = context.Infants.FirstOrDefault(i => i.InfantId == id);

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

            Diaper diaper = new Diaper
            {
                Time     = DateTime.Now,
                InfantId = id
            };

            return(View("DiaperEditor", DiaperViewModelFactory.Create(diaper, infant)));
        }
        public async Task <IActionResult> Delete(long id, Diaper diaper)
        {
            if (!IsLoggedIn())
            {
                return(RedirectToPage("/Account/Login"));
            }

            Diaper preSaveDiaper = context.Diapers.AsNoTracking().Include(f => f.Infant).FirstOrDefault(d => d.DiaperId == id);

            if (!IsDiaperOwner(preSaveDiaper))
            {
                return(RedirectToPage("/Error/Error404"));
            }

            long infantId = diaper.InfantId;

            context.Diapers.Remove(diaper);
            await context.SaveChangesAsync();

            return(RedirectToAction("Index", "Dashboard", new { id = infantId }));
        }
        public async Task <IActionResult> Create([Bind("Id,Notes,Date,Time,Child_Id,Teacher_Id,ChildName,Type")] Diaper diaper)
        {
            if (ModelState.IsValid)
            {
                diaper.Id   = Guid.NewGuid();
                diaper.Date = DateTime.Now;
                string y = diaper.Time.Remove(2, 1);
                string x = DateTime.ParseExact(y, "HHmm", CultureInfo.CurrentCulture).ToString("hh:mm tt");
                diaper.Time = x;
                var teacher = await _context.Teachers.FirstOrDefaultAsync(m => m.Id == diaper.Teacher_Id);

                diaper.TeacherName = teacher.FirstName + " " + teacher.LastName;
                _context.Add(diaper);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { id = diaper.Child_Id }));
            }

            ViewData["Teacher"] = new SelectList(_context.Teachers, "Id", "FirstName", diaper.Teacher_Id);

            return(View(diaper));
        }
        public async Task <IActionResult> Edit(long id, [FromForm] Diaper diaper)
        {
            if (!IsLoggedIn())
            {
                return(RedirectToPage("/Account/Login"));
            }

            Diaper preSaveDiaper = context.Diapers.AsNoTracking().Include(f => f.Infant).FirstOrDefault(d => d.DiaperId == id);

            if (!IsDiaperOwner(preSaveDiaper))
            {
                return(RedirectToPage("/Error/Error404"));
            }

            if (ModelState.IsValid)
            {
                context.Diapers.Update(diaper);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index", "Dashboard", new { id = diaper.InfantId }));
            }
            return(View("DiaperEditor", DiaperViewModelFactory.Edit(diaper, preSaveDiaper.Infant)));
        }
 private bool IsDiaperOwner(Diaper diaper) => diaper.Infant.UserId == userManager.GetUserId(User);
Beispiel #27
0
        public async Task <IActionResult> OnGetAsync(int id)
        {
            DocumentTypes = await Context.DocumentType.ToListAsync();

            Student = await Context.Student
                      .Include(s => s.Parent)
                      .Include(s => s.SignIns)
                      .FirstOrDefaultAsync(m => m.StudentId == id);

            if (Student == null)
            {
                return(NotFound());
            }

            Diapers = await Context.Diapers
                      .Where(d => d.Student == Student && d.Time.Date == DateTime.Today.Date)
                      .Include(d => d.Changer)
                      .ToListAsync();

            Diaper = new Diaper {
                Time = DateTime.Now
            };

            Notes = await Context.StudentNote
                    .Where(n => n.Student == Student && n.Date.Date == DateTime.Today.Date)
                    .Include(n => n.AppUser)
                    .ToListAsync();

            Note = new StudentNote {
                Date = DateTime.Now
            };

            Bottles = await Context.Bottles
                      .Where(d => d.Student == Student && d.Time.Date == DateTime.Today.Date)
                      .Include(b => b.Teacher)
                      .ToListAsync();

            Bottle = new AddBottle {
                Time = DateTime.Now
            };

            var bottleTypeList = await Context.Bottles.Select(b => b.Type).Distinct().ToListAsync();

            BottleTypes = bottleTypeList.Select(x =>
                                                new SelectListItem()
            {
                Text  = x.ToString(),
                Value = x.ToString()
            });


            StudentDocs = await Context.StudentDocuments
                          .Where(d => d.Student == Student)
                          .Include(d => d.UploadUser)
                          .Include(d => d.DocumentType)
                          .ToListAsync();

            ParentName = Student.Parent.FirstName + " " + Student.Parent.LastName;

            var isAuthorized = User.IsInRole(Constants.TeachersRole) ||
                               User.IsInRole(Constants.AdministratorsRole);

            var currentUserId = UserManager.GetUserId(User);

            if (!isAuthorized &&
                currentUserId != Student.ParentID &&
                Student.Status != EnrollmentStatus.Enrolled)
            {
                return(new ChallengeResult());
            }

            return(Page());
        }