public async Task <IActionResult> UpdateClass(ClassCreationDto updatedCLass) { if (!await _repo.IsExistClass(updatedCLass.Id)) { return(BadRequest("Class doesn't Exist")); } var classFromRepo = await _repo.GetClassById(updatedCLass.Id); classFromRepo.Name = updatedCLass.Name; if (await _repo.SaveAll()) { return(Ok()); } throw new Exception($"Updating class {updatedCLass.Id} failed on save"); }
public async Task <IActionResult> AddClass(ClassCreationDto classs) { if (classs.Name == null) { return(BadRequest()); } if (await _repo.IsExistClassName(classs.Name)) { return(BadRequest("class Name already Exist")); } var createdClass = _mapper.Map <Class>(classs); _repo.Add <Class>(createdClass); if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to add class")); }
public IActionResult CreateClass([FromBody] ClassCreationDto classes) { ClassDto cl = crudService.Create(classes, User); return(CreatedAtRoute("GetClass", new { id = cl.ID }, cl)); }