public async Task <ApplicantResponseDto> InsertApplicant(ApplicantInputDto model) { try { var applicantModel = model.MapTo <Applicant>(); applicantModel = _managementUnitOfWork.ApplicantRepository.Create(applicantModel); await _managementUnitOfWork.SaveAsync(); _logger.LogInformation("insert applicant was successful, applicantId: {applicantId}", applicantModel.Id); return(applicantModel.MapTo <ApplicantResponseDto>()); } catch (Exception ex) { _logger.LogError(ex, "inserting applicant failed"); throw; } }
public async Task <EronFile> SaveFileAsync(HttpPostedFileBase file, ApplicationFolder.ApplicationFolderName folderName) { if (file != null && file.ContentLength > 0) { var inputFileName = file.FileName; var fileId = Guid.NewGuid(); var fileName = fileId.ToString(); var fullFolderName = GetFolderName(folderName); if (!Directory.Exists(HttpContext.Current.Server.MapPath(fullFolderName))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(fullFolderName)); } var server = HttpContext.Current.Server.MapPath(fullFolderName); var fileNameWithFolder = Path.Combine(server, fileName); var result = new EronFile() { FileName = inputFileName, FileUrl = fullFolderName + fileName, Id = fileId, FileType = GetFileType(file), UploadDateTime = DateTime.Now }; file.SaveAs(fileNameWithFolder); _unitOfWork.FileRepository.Create(result); await _unitOfWork.SaveAsync(); return(result); } throw new FileNotFoundException("File is not found"); }
public async Task <bool> Delete(long id, string userId) { var entity = await _unitOfWork.WishListRepository.GetByIdAsync(id); if (entity != null && entity.UserId == userId) { _unitOfWork.WishListRepository.Delete(entity); await _unitOfWork.SaveAsync(); return(true); } if (entity == null) { throw new EntityNotFoundException(); } throw new UnauthorizedAccessException(); }