public async Task <IActionResult> CreateClass(CreateClassDto createClassDto) { try { var nClass = await _classAppService.InsertClass(createClassDto); if (nClass > 0) { return(Ok(nClass)); } return(BadRequest("Class Creation Failed")); } catch (Exception ex) { throw ex; } }
public async Task <long> InsertClass(CreateClassDto model) { ClassName className; if (model == null) { throw new ArgumentNullException(nameof(model)); } className = new ClassName { ClassCode = model.ClassCode, Name = model.Name, Category = model.Category, CreatedOn = DateTime.UtcNow, }; await _schoolHubDbContext.ClassName.AddAsync(className); await _schoolHubDbContext.SaveChangesAsync(); return(className.Id); }
public async Task <ActionResult> Create(ClassViewModel classViewModel) { var existingCode = await _classService.FindByCode(classViewModel.ClassCode); if (existingCode == null) { var @class = new CreateClassDto { ClassCode = classViewModel.ClassCode, ClassName = classViewModel.ClassName, Careers = classViewModel.Careers }; await _classService.Create(@class); return(Ok()); } else { return(BadRequest("Ya existe una clase con este codigo")); } }
public async Task <IActionResult> EditClass(int id, CreateClassDto createClassDto) { var classFromRepo = await repo.GetClass(id); if (classFromRepo == null) { return(BadRequest("No Class Found")); } var staff = await repo.GetStaffFromUserName(createClassDto.AttendantUserName); if (staff == null) { return(null); } switch (createClassDto.Facility) { case "1": createClassDto.Facility = "Full Hall"; break; case "2": createClassDto.Facility = "Half Hall"; break; case "3": createClassDto.Facility = "Small Area"; break; } switch (createClassDto.ClassTime) { case "1": createClassDto.ClassTime = "08:00 - 09:00"; break; case "2": createClassDto.ClassTime = "09:00 - 10:00"; break; case "3": createClassDto.ClassTime = "10:00 - 11:00"; break; case "4": createClassDto.ClassTime = "11:00 - 12:00"; break; case "5": createClassDto.ClassTime = "12:00 - 13:00"; break; case "6": createClassDto.ClassTime = "13:00 - 14:00"; break; case "7": createClassDto.ClassTime = "14:00 - 15:00"; break; case "8": createClassDto.ClassTime = "15:00 - 16:00"; break; case "9": createClassDto.ClassTime = "16:00 - 17:00"; break; case "10": createClassDto.ClassTime = "17:00 - 18:00"; break; case "11": createClassDto.ClassTime = "18:00 - 19:00"; break; case "12": createClassDto.ClassTime = "19:00 - 20:00"; break; } mapper.Map(createClassDto, classFromRepo); if (await repo.SaveAll()) { return(NoContent()); } throw new Exception($"Updating class {id} failed on save"); }
public async Task <IActionResult> CreateNewClass(CreateClassDto createClassDto) { var staff = await repo.GetStaffFromUserName(createClassDto.AttendantUserName); if (staff == null) { BadRequest("Staff Member Not Found"); } var allCurrentBookings = await repo.GetBookings(); var allCurrentClasses = await repo.GetClasses(); switch (createClassDto.Facility) { case "1": createClassDto.Facility = "Full Hall"; break; case "2": createClassDto.Facility = "Half Hall"; break; case "3": createClassDto.Facility = "Small Area"; break; } switch (createClassDto.ClassTime) { case "1": createClassDto.ClassTime = "08:00 - 09:00"; break; case "2": createClassDto.ClassTime = "09:00 - 10:00"; break; case "3": createClassDto.ClassTime = "10:00 - 11:00"; break; case "4": createClassDto.ClassTime = "11:00 - 12:00"; break; case "5": createClassDto.ClassTime = "12:00 - 13:00"; break; case "6": createClassDto.ClassTime = "13:00 - 14:00"; break; case "7": createClassDto.ClassTime = "14:00 - 15:00"; break; case "8": createClassDto.ClassTime = "15:00 - 16:00"; break; case "9": createClassDto.ClassTime = "16:00 - 17:00"; break; case "10": createClassDto.ClassTime = "17:00 - 18:00"; break; case "11": createClassDto.ClassTime = "18:00 - 19:00"; break; case "12": createClassDto.ClassTime = "19:00 - 20:00"; break; } if (createClassDto.Facility == "Full Hall") { foreach (var item in allCurrentBookings) { if (item.BookingDate.ToShortDateString().Equals(createClassDto.ClassDate.ToShortDateString()) && item.BookingTime.Equals(createClassDto.ClassTime)) { return(BadRequest("Time Slot Taken")); } } } if (createClassDto.Facility == "Full Hall") { foreach (var item in allCurrentClasses) { if (item.ClassDate.ToShortDateString().Equals(createClassDto.ClassDate.ToShortDateString()) && item.ClassTime.Equals(createClassDto.ClassTime)) { return(BadRequest("Time Slot Booked")); } } } Class newClass = new Class { ClassName = createClassDto.ClassName, ClassDate = createClassDto.ClassDate, ClassTime = createClassDto.ClassTime, Facility = createClassDto.Facility, MaxAttendees = createClassDto.MaxAttendees, TotalAttendees = 0, User = staff, Cost = createClassDto.Cost }; Class createdClass = await repo.CreateNewClass(newClass); return(Ok(createdClass)); }
public IActionResult Put([FromRoute] int id, [FromBody] CreateClassDto classDto) { _repository.UpdateClass(id, classDto); return(Created($"api/classes/{id}", null)); }
public async Task <IActionResult> Post([FromBody] CreateClassDto classDto) { var classId = await _repository.CreateClass(classDto); return(Created($"/api/classes/{classId}", null)); }