예제 #1
0
        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;
            }
        }
예제 #2
0
파일: FileHelper.cs 프로젝트: MRebati/Eron
        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();
        }