public bool AddClassType(ClassTypeDto dto) { try { var classType = new ClassType { Id = dto.Id, IsActive = true, ClassColour = dto.ClassColour, Name = dto.Name, Description = dto.Description, Difficulty = dto.Difficulty, ImageFileName = dto.ImageFileName }; _context.ClassTypes.Add(classType); _context.SaveChanges(); _logger.Info($"ClassType {classType.Name} successfully created"); return(true); } catch (Exception e) { _logger.Error(e); return(false); } }
public bool AddClassTimetable(ClassTimetableDto dto) { try { var classType = _context.ClassTypes.FirstOrDefault(x => x.Name == dto.ClassTypeName); if (classType == null) { _logger.Warn($"ClassType name {dto.ClassTypeName} does not match anything found in database"); return(false); } var classTimetable = new ClassTimetable() { Id = Guid.NewGuid().ToString(), ClassType = classType, ClassTypeId = classType.Id, Weekday = dto.Weekday, StartTime = new DateTime(2000, 1, 1, dto.StartHour, dto.StartMinutes, 0), EndTime = new DateTime(2000, 1, 1, dto.EndHour, dto.EndMinutes, 0) }; _context.ClassTimetable.Add(classTimetable); _context.SaveChanges(); _logger.Info($"ClassTimetable {classTimetable.ClassType.Name} starting at {classTimetable.StartTime.ToShortTimeString()} on {classTimetable.Weekday} has been successfully created"); return(true); } catch (Exception e) { _logger.Error(e); return(false); } }
public bool AddHoliday(HolidayDto dto) { try { if (dto == null) { _logger.Warn("Parameter passed is null"); return(false); } var holiday = new Holidays() { HolidaysId = dto.Id, Name = dto.Name, HolidayDate = dto.HolidayDate }; _context.Holiday.Add(holiday); _context.SaveChanges(); _logger.Info($"Holiday {dto.Name} on {dto.HolidayDate} has been successfully created"); return(true); } catch (Exception e) { _logger.Error(e); return(false); } }
public bool DeleteUser(GymUserDto dto) { try { if (dto == null) { _logger.Warn("Parameter passed is null"); return(false); } var user = _context.Users.FirstOrDefault(x => x.Id == dto.Id); if (user == null) { _logger.Warn($"User ID {dto.Id} not found in database"); return(false); } // if instructor, remove association between user and scheduled class. do no remove scheduled class var scheduledClasses = _context.ScheduledClasses.Where(x => x.InstructorId == dto.Id).ToList(); if (scheduledClasses != null && scheduledClasses.Any()) { scheduledClasses.ForEach(sc => { sc.InstructorId = null; }); _logger.Info($"Instructor ID {dto.Id} removed from scheduled classes with IDs {scheduledClasses.Select(x => x.Id).ToList()}"); } // remove associated attendances var attendances = _context.ClassAttendances.Where(x => x.AttendeeId == dto.Id).ToList(); if (attendances != null && attendances.Any()) { _context.ClassAttendances.RemoveRange(attendances); _logger.Info($"Gym user ID {dto.Id} unsigned from class attendances with IDs {attendances.Select(x => x.Id).ToList()}"); } //remove userroles var userRoles = _context.UserRoles.Where(x => x.UserId == dto.Id).ToList(); _context.UserRoles.RemoveRange(userRoles); _context.Users.Remove(user); _context.SaveChanges(); _logger.Info($"Gym user ID {dto.Id} successfully deleted"); return(true); } catch (Exception e) { _logger.Error(e); return(false); } }
public bool AddScheduledClass(ScheduledClassDto dto) { try { if (dto == null) { _logger.Warn("Parameter passed is null"); return(false); } var instructor = _context.Users.FirstOrDefault(x => x.UserName == dto.InstructorName); var classType = _context.ClassTypes.FirstOrDefault(x => x.Name == dto.ClassTypeName); if (instructor == null || classType == null) { _logger.Warn($"Instructor {dto.InstructorName} or ClassType {dto.ClassTypeName} not found in database"); return(false); } var scheduledClass = new ScheduledClass() { Id = dto.Id, Instructor = instructor, InstructorId = instructor.Id, ClassStartTime = dto.ClassStartTime, ClassType = classType, ClassTypeId = classType.Id, IsCancelled = dto.IsCancelled }; _context.ScheduledClasses.Add(scheduledClass); _context.SaveChanges(); _logger.Info($"ScheduledClass ID {dto.Id}, for ClassType {classType.Name} has been scheduled for {scheduledClass.ClassStartTime}"); return(true); } catch (Exception e) { _logger.Error(e); return(false); } }
private void SeedInitialClassTimetable(ProperArch01DbContext context) { context.ClassTimetable.AddOrUpdate( new ClassTimetable { Id = "B95FD7FE-748C-40B3-A2EE-407AFFB8335D", ClassTypeId = "2A19AFC2-B48D-4A9A-B329-DDC0A2827A39", StartTime = new DateTime(2000, 1, 1, 9, 0, 0), EndTime = new DateTime(2000, 1, 1, 10, 0, 0), Weekday = DayOfWeek.Monday } ); context.ClassTimetable.AddOrUpdate( new ClassTimetable { Id = "D3915514-6D05-4D6B-8DB9-DFB5D06BFB10", ClassTypeId = "2A19AFC2-B48D-4A9A-B329-DDC0A2827A39", StartTime = new DateTime(2000, 1, 1, 9, 0, 0), EndTime = new DateTime(2000, 1, 1, 10, 0, 0), Weekday = DayOfWeek.Wednesday } ); context.ClassTimetable.AddOrUpdate( new ClassTimetable { Id = "DBECDEBE-4B79-4B9E-BE41-F446EB1D5987", ClassTypeId = "2A19AFC2-B48D-4A9A-B329-DDC0A2827A39", StartTime = new DateTime(2000, 1, 1, 9, 0, 0), EndTime = new DateTime(2000, 1, 1, 10, 0, 0), Weekday = DayOfWeek.Friday } ); context.ClassTimetable.AddOrUpdate( new ClassTimetable { Id = "5D1ED194-C83A-42C2-BF5F-8C44B3987D6C", ClassTypeId = "E46A1C73-8E07-47E4-8B47-E16922EB0C8F", StartTime = new DateTime(2000, 1, 1, 11, 0, 0), EndTime = new DateTime(2000, 1, 1, 12, 0, 0), Weekday = DayOfWeek.Tuesday } ); context.ClassTimetable.AddOrUpdate( new ClassTimetable { Id = "44C5A47F-E449-47AC-910A-429249A73B63", ClassTypeId = "E05D837C-0D7C-440E-BE69-F7EB4D5F595A", StartTime = new DateTime(2000, 1, 1, 15, 0, 0), EndTime = new DateTime(2000, 1, 1, 16, 0, 0), Weekday = DayOfWeek.Saturday } ); context.SaveChanges(); }
public bool AddClassAttendance(ClassAttendanceDto dto) { try { var attendee = _context.Users.FirstOrDefault(x => x.Id == dto.AttendeeId); var scheduledClass = _context.ScheduledClasses.FirstOrDefault(x => x.Id == dto.ScheduledClassId); if (attendee == null || scheduledClass == null) { _logger.Warn($"Attendee ID {dto.AttendeeId} or ScheduledClass ID {dto.ScheduledClassId} not found in database"); return(false); } var classAttendance = new ClassAttendance() { Id = dto.Id, EnrolledDate = dto.EnrolledDate, EnrolledBy = dto.EnrolledBy, AttendeeId = dto.AttendeeId, Attendee = attendee, ScheduledClass = scheduledClass, ScheduledClassId = dto.ScheduledClassId, NoShow = dto.NoShow }; _context.ClassAttendances.Add(classAttendance); _context.SaveChanges(); return(true); } catch (Exception e) { _logger.Error(e); return(false); } }
private void SeedInitialClassTypes(ProperArch01DbContext context) { context.ClassTypes.AddOrUpdate( new ClassType { Id = "2A19AFC2-B48D-4A9A-B329-DDC0A2827A39", Name = "Barbell Blast", Difficulty = 80, IsActive = true, ClassColour = Colours.Colour.GoldenRod, Description = "This class is for anyone looking to get lean, toned and fit – fast. Using light to moderate weights with lots of repetition, barbell blast gives you a total body workout. You’ll leave the class feeling challenged and motivated, ready to come back for more.", ImageFileName = "barbell-power-sm.jpg" } ); context.ClassTypes.AddOrUpdate( new ClassType { Id = "E46A1C73-8E07-47E4-8B47-E16922EB0C8F", Name = "Rebel Training", Difficulty = 90, IsActive = true, ClassColour = Colours.Colour.Red, Description = "A high intensity cardio, strength and conditioning class that will push your body to its upper limits. You will get the ultimate body workout, pushing yourself further and performing at a higher intensity. (This class is recommended for those with a good level of fitness).", ImageFileName = "mlc-rebel-sm.jpg" } ); context.ClassTypes.AddOrUpdate( new ClassType { Id = "E05D837C-0D7C-440E-BE69-F7EB4D5F595A", Name = "Fab Abs", Difficulty = 60, IsActive = true, ClassColour = Colours.Colour.SkyBlue, Description = "This is a 30 minute intense workout for your core where you will learn new exercises to help sculpt the body. This class is for all fitness levels and is a great way to fit a quick but challenging workout into your busy day.", ImageFileName = "mlc-abs.jpg" } ); context.SaveChanges(); }