示例#1
0
        public async Task <ActionResult <EditGymClassRequest> > editClass(EditGymClassRequest edit)
        {
            Users user = await userRepository.getUser(edit.EditorUsername);

            if (user == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound, "User making the edit to the class was not found!"));
            }

            if (user.UserType != UserTypes.Manager && user.UserType != UserTypes.Instructor)
            {
                return(StatusCode(StatusCodes.Status401Unauthorized, "User making the edit is not a manager or instructor!"));
            }

            GymClasses target = await classRepository.getClassById(edit.ClassId);

            if (target == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound, "The class you wish to edit does not exist!"));
            }

            ClassMappers.editRequestToGymClassModel(edit, target);

            target = await classRepository.editClass(target);

            if (target != null)
            {
                return(ClassMappers.classToClassRequestModel(target));
            }
            else
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Something went wrong trying to update the class!"));
            }
        }
示例#2
0
 public static void editRequestToGymClassModel(EditGymClassRequest source, GymClasses target)
 {
     target.ClassId            = source.ClassId;
     target.InstructorUsername = source.InstructorUsername;
     target.Name        = source.Name;
     target.Description = source.Description;
     target.Day         = source.Day;
     target.StartTime   = source.StartTime;
     target.EndTime     = source.EndTime;
     target.MaxCapacity = source.MaxCapacity;
     target.Cancelled   = source.Cancelled;
 }
示例#3
0
        public static EditGymClassRequest classToClassRequestModel(GymClasses source)
        {
            EditGymClassRequest target = new EditGymClassRequest();

            target.ClassId            = source.ClassId;
            target.InstructorUsername = source.InstructorUsername;
            target.Name        = source.Name;
            target.Description = source.Description;
            target.Day         = source.Day;
            target.StartTime   = source.StartTime;
            target.EndTime     = source.EndTime;
            target.MaxCapacity = source.MaxCapacity;
            target.Cancelled   = source.Cancelled;

            return(target);
        }