public async Task <IActionResult> Edit(int id, DownloadDTO downloadDto) { if (id != downloadDto.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var edited = await _apiService.UpdateAsync <Download, DownloadDTO>(downloadDto); } catch { } return(RedirectToAction(nameof(Index))); } var moduleDto = await _apiService.GetAsync <Module, ModuleDTO>(true); ViewData["ModuleId"] = new SelectList(moduleDto, "Id", "ModuleTitle"); var courseDto = await _apiService.GetAsync <Course, CourseDTO>(true); ViewData["CourseId"] = new SelectList(courseDto, "Id", "CourseTitle"); return(View(downloadDto)); }
public async Task <ActionResult <DownloadDTO> > PutDownload(int id, DownloadDTO model) { try { if (model == null) { return(BadRequest("No entity provided")); } if (!id.Equals(model.Id)) { return(BadRequest("Differing Ids")); } var exist = await _crudService.AnyAsync <Course>(c => c.Id.Equals(model.CourseId)); var exist1 = await _crudService.AnyAsync <Module>(m => m.Id.Equals(model.ModuleId)); if (!exist && !exist1) { return(NotFound("Cant find related id in VideoDTO")); } if (await _crudService.UpdateAsync <DownloadDTO, Download>(model)) { return(NoContent()); } } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to add the entity")); } return(BadRequest("Cannot update")); }
public async Task <IActionResult> Put(int moduleId, int courseId, int id, DownloadDTO model) { if (model == null) { return(BadRequest("Missing entity")); } if (!id.Equals(model.Id)) { return(BadRequest("Differing ids")); } if (model.Title.IsNullOrEmptyOrWhiteSpace()) { return(BadRequest("Title is required")); } try { var exist = await _adminService.AnyAsync <Module>(c => c.Id.Equals(moduleId)); if (!exist) { return(NotFound("Could not find related entity")); } exist = await _adminService.AnyAsync <Course>(c => c.Id.Equals(courseId)); if (!exist) { return(NotFound("Could not find related entity")); } exist = await _adminService.AnyAsync <Module>(c => c.Id.Equals(courseId) && c.Id.Equals(moduleId)); if (!exist) { return(NotFound("Could not find related entity")); } exist = await _adminService.AnyAsync <Download>(c => c.Id.Equals(id)); if (!exist) { return(NotFound("Could not find entity")); } if (await _adminService.UpdateAsync <DownloadDTO, Download>(model)) { return(NoContent()); } } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to update the entity")); } return(BadRequest("Unable to update the entity")); }
public User GenerateNewUserFromDTO(UploadDTO uploadDTO = null, DownloadDTO downloadDTO = null) { if (uploadDTO == null && downloadDTO == null) { throw new ArgumentNullException(); } return(new User() { Name = uploadDTO.DeveloperName, Surname = uploadDTO.DeveloperSurname, Email = uploadDTO.Email }); }
public async Task <ActionResult> Put(int id, int courseId, int moduleId, DownloadDTO model) { try { if (model == null) { return(BadRequest("No entity provided")); } if (!id.Equals(model.Id)) { return(BadRequest("Differing ids")); } if (model.Title.IsNullOrEmptyOrWhiteSpace()) { return(BadRequest("Title is required")); } var exists = await _db.AnyAsync <Course>(a => a.Id.Equals(model.CourseId)); if (!exists) { return(NotFound("Could not find related entity")); } exists = await _db.AnyAsync <Module>(a => a.Id.Equals(moduleId) && a.CourseId.Equals(courseId)); if (!exists) { return(NotFound("Could not find related entity")); } exists = await _db.AnyAsync <Download>(a => a.Id.Equals(id)); if (!exists) { return(NotFound("Could not find entity")); } var success = await _db.UpdateAsync <DownloadDTO, Download>(model); if (success) { return(NoContent()); } } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to update entity")); } return(BadRequest("Unable to update the entity")); }
public async Task <ActionResult <DownloadDTO> > PostDownload(DownloadDTO model) { try { if (model == null) { return(BadRequest("No entity provided")); } var exist = await _crudService.AnyAsync <Course>(c => c.Id.Equals(model.CourseId)); var exist1 = await _crudService.AnyAsync <Module>(m => m.Id.Equals(model.ModuleId)); if (!exist && !exist1) { return(NotFound("Cant find related id in VideoDTO")); } var id = await _crudService.CreateAsync <DownloadDTO, Download>(model); if (id < 1) { return(BadRequest("Unable to add the entity")); } var Dto = await _crudService.GetSingleAsync <Download, DownloadDTO>(s => s.Id.Equals(id), true); if (Dto == null) { return(BadRequest("Cannot create entity")); } var uri = _linkGenerator.GetPathByAction("GetSingleDownload", "Downloads", new { id }); return(Created(uri, Dto)); } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "Server Failure!")); } }
public async Task <IActionResult> Create(DownloadDTO downloadDto) { if (ModelState.IsValid) { var createdId = await _apiService.CreateAsync <Download, DownloadDTO>(downloadDto); return(RedirectToAction(nameof(Index))); } var courseDto = await _apiService.GetAsync <Course, CourseDTO>(true); ViewData["CourseId"] = new SelectList(courseDto, "Id", "CourseTitle", downloadDto.CourseId); var moduleDto = await _apiService.GetAsync <Module, ModuleDTO>(true); ViewData["ModuleId"] = new SelectList(moduleDto, "Id", "ModuleTitle", downloadDto.ModuleId); return(View(downloadDto)); }
//Adds a Downloads object public void AddDownload(DownloadDTO downloadDTO) { //***************************************************** var tempUser = new User() { Name = downloadDTO.UserName, Surname = downloadDTO.UserSurname, Email = downloadDTO.Email }; //Add to Users User tempTempUser = _userRepository.AddEntityReturned(tempUser); tempUser = tempTempUser; //***************************************************** var tempApp = new App() { Name = downloadDTO.AppName, Genre = downloadDTO.Genre, LastUpdate = downloadDTO.LastUpdate, AppBrand = downloadDTO.AppBrand }; //Add to Apps App tempTempApp = _appRepository.AddEntityReturned(tempApp); //Updates the object of type Apps tempApp = tempTempApp; //***************************************************** var tempCompatibility = new Compatibilities() { DeviceType = downloadDTO.DeviceType }; //Add to Compatibilities Compatibilities tempTempCompatibility = _compatibilityRepository.AddEntityReturned(tempCompatibility); tempCompatibility = tempTempCompatibility; //***************************************************** var tempPrice = new Prices() { Currency = downloadDTO.Currency, Value = downloadDTO.Value }; //Add to Prices Prices tempTempPrice = _priceRepository.AddEntityReturned(tempPrice); tempPrice = tempTempPrice; //***************************************************** var tempUserApp = new UserApp() { UsersId = tempUser.Id, AppsId = tempApp.Id }; //Add to UserApp UserApp tempTempUserApp = _userAppRepository.AddEntityReturned(tempUserApp); tempUserApp = tempTempUserApp; //***************************************************** var tempDownloads = new Downloads() { Successful = downloadDTO.Successful }; //Add to Uploads Downloads tempTempUploads = _downloadRepository.AddEntityReturned(tempDownloads); tempDownloads = tempTempUploads; //***************************************************** }
public async Task <ActionResult <DownloadDTO> > Post(int courseId, int moduleId, DownloadDTO model) { try { if (courseId.Equals(0)) { courseId = model.CourseId; } if (moduleId.Equals(0)) { moduleId = model.ModuleId; } if (model == null) { return(BadRequest("No entity provided")); } if (!model.CourseId.Equals(courseId)) { return(BadRequest("Differing ids")); } if (model.Title.IsNullOrEmptyOrWhiteSpace()) { return(BadRequest("Title is required")); } var exists = await _db.AnyAsync <Course>(a => a.Id.Equals(courseId)); if (!exists) { return(NotFound("Could not find related entity")); } exists = await _db.AnyAsync <Module>(a => a.Id.Equals(moduleId) && a.CourseId.Equals(courseId)); if (!exists) { return(BadRequest("Could not find related entity")); } var id = await _db.CreateAsync <DownloadDTO, Download>(model); if (id < 1) { return(BadRequest("Unable to add the entity")); } var dto = await _db.SingleAsync <Download, DownloadDTO>(s => s.CourseId.Equals(courseId) && s.ModuleId.Equals(moduleId) && s.Id.Equals(id)); if (dto == null) { return(BadRequest("Unable to add the entity")); } var uri = _linkGenerator.GetPathByAction("Get", "Downloads", new { id, courseId, moduleId }); return(Created(uri, dto)); } catch { return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to add the entity")); } }
public async Task <ActionResult <DownloadDTO> > Post(int moduleId, int courseId, DownloadDTO model) { if (moduleId.Equals(0)) { moduleId = model.ModuleId; } if (courseId.Equals(0)) { courseId = model.CourseId; } if (model == null) { return(BadRequest("No entity provided")); } if (model.Title.IsNullOrEmptyOrWhiteSpace()) { return(BadRequest("Title is required")); } try { var courseExist = await _adminService.AnyAsync <Course>(c => c.Id.Equals(courseId)); if (!courseExist) { return(NotFound("Could not find related entity")); } var moduleExist = await _adminService.AnyAsync <Module>(m => m.Id.Equals(moduleId) && m.CourseId.Equals(courseId)); if (!courseExist) { return(NotFound("Could not find related entity")); } if (!model.CourseId.Equals(courseId)) { return(BadRequest("Differing ids")); } var id = await _adminService.CreateAsync <DownloadDTO, Download>(model); if (id < 1) { return(BadRequest("Unable to add the entity")); } var dto = await _adminService.SingleAsync <Download, DownloadDTO>(v => v.ModuleId.Equals(moduleId) && v.CourseId.Equals(courseId) && v.Id.Equals(id)); if (dto == null) { return(BadRequest("Unable to add the entity")); } var uri = _linkGenerator.GetPathByAction("Get", "Downloads", new { id, courseId, moduleId }); return(Created(uri, dto)); } catch (Exception ex) { _logger.LogError(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to add the entity")); } }