예제 #1
0
        public Booking UpdateBooking(int bookingId, BookingDto dto)
        {
            TrainingClass t = _context.TrainingClasses.Where(x => x.TrainingClassId == dto.TrainingClassId).FirstOrDefault();

            if (t == null)
            {
                return(null);
            }

            Booking b = _context.Bookings.Where(x => x.BookingId == bookingId).FirstOrDefault();

            if (b == null)
            {
                return(null);
            }

            b.Date            = t.Start;
            b.GymId           = dto.GymId;
            b.Timestamp       = DateTime.Now;
            b.TrainerId       = dto.TrainerId;
            b.TrainingClassId = dto.TrainingClassId;
            b.UserId          = dto.UserId;

            _context.Bookings.Update(b);
            _context.SaveChanges();

            return(b);
        }
            public async Task <Unit> Handle(CreateCommand request, CancellationToken cancellationToken)
            {
                var user = await _context.Users.FirstOrDefaultAsync(x => x.UserName == _userAccessor.GetCurrentUsername());

                if (user == null)
                {
                    throw new ErrorException(HttpStatusCode.Unauthorized);
                }
                if (request.Time != null)
                {
                    if (TimeConverter.InvalidTime(TimeConverter.TimeToMins(request.Time)))
                    {
                        throw new ErrorException(HttpStatusCode.BadRequest, new { TrainingClasses = "Invalid Time" });
                    }
                }
                var TrainingClass = new TrainingClass
                {
                    Id          = request.Id,
                    Title       = request.Title,
                    Description = request.Description,
                    Category    = request.Category,
                    Time        = TimeConverter.TimeToMins(request.Time),
                    DayOfWeek   = request.DayOfWeek,
                    City        = request.City,
                    Address     = request.Address,
                    Country     = request.Country,
                    PostalCode  = request.PostalCode,
                    Province    = request.Province,
                    TotalSpots  = request.TotalSpots
                };

                if (request.Id != null)
                {
                    var trainingClass = await _context.TrainingClasses.FindAsync(request.Id);

                    if (trainingClass != null)
                    {
                        TrainingClass.Id = Guid.NewGuid();
                    }
                }

                _context.TrainingClasses.Add(TrainingClass);
                _context.UserTrainingClasses.Add(new UserTrainingClass
                {
                    User          = user,
                    TrainingClass = TrainingClass,
                    DateJoined    = DateTime.Now,
                    IsHost        = true
                });
                if (await _context.SaveChangesAsync() > 0)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving changes");
            }
예제 #3
0
 static void PrintClassInformation(TrainingClass trainingClass)
 {
     Console.WriteLine($"Class {trainingClass.ClassName} information ");
     Console.WriteLine($"Teacher information: \n{trainingClass.Teacher}");
     Console.WriteLine($"{trainingClass.GetCountStudent()} students in the class, students informations:");
     foreach (Student student in trainingClass.Students)
     {
         Console.WriteLine($"Student: {student}");
     }
 }
예제 #4
0
        public TrainingClass DeleteTrainingClass(int trainingClassId)
        {
            List <Booking> b = _context.Bookings.Where(x => x.TrainingClassId == trainingClassId).ToList();
            TrainingClass  t = _context.TrainingClasses.Where(x => x.TrainingClassId == trainingClassId).FirstOrDefault();

            if (t == null)
            {
                return(null);
            }

            _context.TrainingClasses.Remove(t);
            b.ForEach(x => _context.Bookings.Remove(x));
            _context.SaveChanges();
            return(t);
        }
        public IActionResult GetTrainingClass(int Id)
        {
            Log.Information($"Attempting to retrieve training class. Id: {Id}.");
            TrainingClass t = _TrainingClassService.GetTrainingClass(Id);

            if (t == null)
            {
                Log.Error("Failed to retrieve training class.");
                return(BadRequest());
            }
            else
            {
                Log.Information("Training class retrieved successfully." + t);
                return(Ok(t));
            }
        }
        public IActionResult UpdateTrainingClass(int TrainingClassId, TrainingClassDto dto)
        {
            Log.Information("Attempting to update training class.");
            TrainingClass t = _TrainingClassService.UpdateTrainingClass(TrainingClassId, dto);

            if (t == null)
            {
                Log.Error("Failed to update training class.");
                return(BadRequest());
            }
            else
            {
                Log.Information("Training class updated successfully. " + t);
                return(Ok(t));
            }
        }
        public IActionResult CreateTrainingClass(TrainingClassDto dto)
        {
            Log.Information("Attempting to create training class.");
            TrainingClass t = _TrainingClassService.CreateTrainingClass(dto);

            if (t == null)
            {
                Log.Error("Failed to create training class.");
                return(BadRequest());
            }
            else
            {
                Log.Information("Training class created successfully. " + t);
                return(Created("Training class created successfully.", t));
            }
        }
예제 #8
0
        public TrainingClass CreateTrainingClass(TrainingClassDto dto)
        {
            TrainingClass tc = new TrainingClass()
            {
                GymId       = dto.GymId,
                Name        = dto.Name,
                TrainerId   = dto.TrainerId,
                MaxPeople   = dto.MaxPeople,
                Description = dto.Description,
                Start       = dto.Start,
                End         = dto.End
            };

            _context.TrainingClasses.Add(tc);
            _context.SaveChanges();
            return(tc);
        }
예제 #9
0
        static void Main()
        {
            Console.OutputEncoding = Encoding.Unicode;

            List <Student> studentsListFirst = new List <Student>
            {
                new Student(2018, "Alex", 18, 92),
                new Student(2018, "Boris", 18, 85),
                new Student(2018, "Jack", 19, 75),
                new Student(2018, "Amelia", 18, 58),
                new Student(2018, "Lily", 19, 60)
            };

            Teacher       firstTeacher       = new Teacher("History", new DateTime(2011, 5, 1), 3500, "Gerald Hall", 35, 87);
            TrainingClass trainingClassFirst = new TrainingClass(studentsListFirst, firstTeacher, "History A51");

            PrintClassInformation(trainingClassFirst);

            #region Change entities for test

            studentsListFirst[0].SetWright(91);
            studentsListFirst[1].SetName("Oscar");              //Boris change name
            studentsListFirst[1].SetWright(89);                 //Boris put on weight
            studentsListFirst[3].SetWright(59);

            foreach (Student student in studentsListFirst)
            {
                student.AddOneYearAge();
                student.IncreaseYearOfStudy();
            }


            firstTeacher.ChangeAcademicSubject("History and history of the English language");
            firstTeacher.AddSalary(500);
            firstTeacher.AddOneYearAge();

            #endregion

            Console.WriteLine("\nShow new information for test:\n");
            PrintClassInformation(trainingClassFirst);
            Console.ReadLine();
        }
예제 #10
0
        public TrainingClass UpdateTrainingClass(int trainingClassId, TrainingClassDto dto)
        {
            TrainingClass t = _context.TrainingClasses.Where(x => x.TrainingClassId == trainingClassId).FirstOrDefault();

            if (t == null)
            {
                return(null);
            }

            t.Name        = dto.Name;
            t.GymId       = dto.GymId;
            t.MaxPeople   = dto.MaxPeople;
            t.TrainerId   = dto.TrainerId;
            t.Description = dto.Description;
            t.Start       = dto.Start;
            t.End         = dto.End;
            _context.Update(t);
            _context.SaveChanges();
            return(t);
        }
예제 #11
0
        public Booking CreateBooking(BookingDto dto)
        {
            TrainingClass t = _context.TrainingClasses.Where(x => x.TrainingClassId == dto.TrainingClassId).FirstOrDefault();

            if (t == null)
            {
                return(null);
            }
            Booking b = new Booking()
            {
                GymId           = dto.GymId,
                UserId          = dto.UserId,
                TrainerId       = dto.TrainerId,
                Timestamp       = DateTime.Now,
                Date            = t.Start,
                TrainingClassId = dto.TrainingClassId
            };

            _context.Bookings.Add(b);
            _context.SaveChanges();
            return(b);
        }
예제 #12
0
        public ViewResult CreateOccurrence(Models.Training.TrainingClassInsert trainingClassInsert)
        {
            Models.DB.TrainingClass trainingClass = new TrainingClass();                                                         //the class itself
            List <Models.Training.TrainingClassParticipant> students    = new List <Models.Training.TrainingClassParticipant>(); //the students' participation in the above training class
            List <Models.Training.TrainingClassParticipant> instructors = new List <Models.Training.TrainingClassParticipant>(); //the instructors' participation in the above training class
            var x      = HttpContext.Request.Form;
            var thanks = new Models.Training.TrainingClassInsertConfirmation();

            Int32 i = 0;
            Int32 j = 0;

            //gross, but looping through the form data to find students/instructors/hours, not using binding for this
            foreach (var item in x)
            {
                if (item.Key == "member")
                {
                    foreach (var y in item.Value)
                    {
                        //gets the memberid
                        Models.Training.TrainingClassParticipant topi = new Models.Training.TrainingClassParticipant();
                        String maybememberid = y.ToString();
                        topi.MemberID = Int32.Parse(y.ToString());

                        //get the hours
                        string maybeHours = x["hours"][i];
                        topi.Hours = Decimal.Parse(maybeHours);

                        //keeping a counter so (above) we know how to find the hours by index. ie: for the third member, we look for the third set of hours.
                        students.Add(topi);
                        i = i + 1;
                    }
                }

                if (item.Key == "instructor")
                {
                    foreach (var y in item.Value)
                    {
                        //gets the memberid
                        Models.Training.TrainingClassParticipant topi = new Models.Training.TrainingClassParticipant();
                        String maybememberid = y.ToString();
                        topi.MemberID = Int32.Parse(y.ToString());

                        //get the hours
                        string maybeHours = x["ihours"][j];
                        topi.Hours = Decimal.Parse(maybeHours);

                        //keeping a counter so (above) we know how to find the hours by index. ie: for the third member, we look for the third set of hours.
                        instructors.Add(topi);
                        j = j + 1;
                    }
                }
            }


            trainingClass.Created                 = DateTime.UtcNow;
            trainingClass.TrainingDate            = trainingClassInsert.TrainingDate;
            trainingClass.TrainingId              = trainingClassInsert.TrainingID;
            trainingClass.TrainingClassStudent    = new List <TrainingClassStudent>();
            trainingClass.TrainingClassInstructor = new List <TrainingClassInstructor>();


            //parse the form and grab the instructors and students, along with their hours objects to store
            foreach (var item in students)
            {
                Models.DB.TrainingClassStudent trainingClassStudent = new TrainingClassStudent();

                trainingClassStudent.Created = DateTime.UtcNow;
                trainingClassStudent.TrainingClassStudentMemberId = item.MemberID;
                trainingClassStudent.TrainingClassStudentHours    = item.Hours;

                trainingClass.TrainingClassStudent.Add(trainingClassStudent);
            }

            foreach (var item in instructors)
            {
                Models.DB.TrainingClassInstructor trainingClassInstructor = new TrainingClassInstructor();

                trainingClassInstructor.Created = DateTime.UtcNow;
                trainingClassInstructor.TrainingClassInstructorMemberId = item.MemberID;
                trainingClassInstructor.TrainingClassStudentHours       = item.Hours;

                trainingClass.TrainingClassInstructor.Add(trainingClassInstructor);
            }


            try
            {
                _context.Add(trainingClass);
                _context.SaveChanges();
            }
            catch (Exception exc)
            {
                throw new Exception("Error saving new class (EF): " + exc.ToString());
            }


            var hours  = students.Sum(item => item.Hours).ToString();
            var people = students.Count.ToString();

            thanks.Message = "Great work, your team has added " + hours + " hours of training across " + people + " members.";

            return(View("TrainingOccurrenceInsertConfirmation", thanks));
        }