public async Task <ActionResultDto <ModuleRunDto> > CreateModuleRun(ModuleRunDto moduleRunDto) { var moduleRun = new ModuleRun(); mapper.Map(moduleRunDto, moduleRun); if (moduleRun == null) { return(new ActionResultDto <ModuleRunDto>("You can not add an empty module run ")); } foreach (var mr in _context.ModuleRuns) { if ((mr.ModuleId == moduleRun.ModuleId) && (mr.Code == moduleRun.Code) && (mr.Place == moduleRun.Place) && (mr.SemesterId == moduleRun.SemesterId)) { return(new ActionResultDto <ModuleRunDto>("This Module run is already" + "exist in this semester.")); } } var result = await _context.ModuleRuns.AddAsync(moduleRun); await _context.SaveChangesAsync(); return(mapper.Map <ModuleRunDto>(result.Entity)); }
public async Task <ActionResult <ModuleRunDto?> > UpdateModuleRun(ModuleRunDto moduleRun) { try { var updatedModuleRun = await _moduleRunService.GetModuleRun(moduleRun.ModuleRunId); if (updatedModuleRun == null) { return(NotFound($"Module run with id = {moduleRun.ModuleRunId } was not found!")); } return(await _moduleRunService.UpdateModuleRun(moduleRun)); } catch (Exception ex) { _logger.LogError(SR.ErrorRetrievingDataFromDataBase, ex); return(StatusCode(StatusCodes.Status500InternalServerError, SR.ErrorUpdatingDatabase)); } }
public async Task <ModuleRunDto?> UpdateModuleRun(ModuleRunDto moduleRunDto) { var moduleRun = await _context.ModuleRuns.FindAsync(moduleRunDto.ModuleRunId); if (moduleRun != null) { moduleRun.ModuleRunId = moduleRunDto.ModuleRunId; moduleRun.Code = moduleRunDto.Code; moduleRun.ModuleId = moduleRunDto.ModuleId; moduleRun.Place = moduleRunDto.Place; moduleRun.SemesterId = moduleRunDto.SemesterId; moduleRun.isSelected = moduleRunDto.isSelected; await _context.SaveChangesAsync(); return(mapper.Map <ModuleRunDto>(moduleRun)); } return(null); }
public async Task <ModuleRunDto> UpdateModuleRun(ModuleRunDto moduleRun) { return(await httpClient.PutJsonAsync <ModuleRunDto>("api/modulerun", moduleRun)); }
public async Task <ActionResultDto <ModuleRunDto> > CreateModuleRun(ModuleRunDto newModuleRun) { return(await httpClient.PostJsonAsync <ModuleRunDto>("api/modulerun", newModuleRun)); }
public async Task <ActionResultDto <ModuleRunDto> > CreateModuleRun(ModuleRunDto mr) { return(await _moduleRunService.CreateModuleRun(mr)); }