예제 #1
0
        public IActionResult AddFirmJobPost(JobPostDTO model)
        {
            var firm = _firmService.GetFirmById(model.FirmId);

            if (string.IsNullOrEmpty(firm.Id))
            {
                return(OK(StatusCodeType.FIRM_NOTFOUND, StatusMessage.FIRM_NOTFOUND, false));
            }

            var response = _firmService.AddFirmJobPost(model);

            if (response == null)
            {
                return(OK(StatusCodeType.HAS_EXCEPTION, StatusMessage.HAS_EXCEPTION, false));
            }

            return(OK(StatusCodeType.SUCCESS, StatusMessage.SUCCESS, response));
        }
예제 #2
0
        public async Task <IActionResult> ChangeLogo(IFormFile file)
        {
            if (file == null)
            {
                return(BadRequest("Logo seçilmedi"));
            }

            var firmFolder = string.Empty; var path = string.Empty; var logo = string.Empty; var oldFilepath = string.Empty;

            var fileName = Guid.NewGuid().ToString() + Path.GetExtension(file.FileName);

            var firm = _firmService.GetFirmById(_currentUser.FirmId);

            if (firm == null)
            {
                return(BadRequest("Firma bulunamadı"));
            }

            var isAdmin = _userManager.IsInRoleAsync(_currentUser_, "Admin").Result;

            if (isAdmin)
            {
                firmFolder  = "admin";
                path        = Path.Combine(_hostingEnvironment.WebRootPath, "files", firmFolder);
                logo        = string.Format("/files/admin/{0}", fileName);
                oldFilepath = Path.Combine(path, firm.LogoPath.Split('/')[3]);
            }

            var isFirm = _userManager.IsInRoleAsync(_currentUser_, "Firm").Result;

            if (isFirm)
            {
                firmFolder  = _firmService.GetFirmById(firm.Id).LogoPath.Split('/')[3];
                path        = Path.Combine(_hostingEnvironment.WebRootPath, "files", "firms", firmFolder);
                logo        = string.Format("/files/firms/{0}/{1}", firmFolder, fileName);
                oldFilepath = Path.Combine(path, firm.LogoPath.Split('/')[4]);
            }

            // yeni dosyayı kaydet
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            var filePath = Path.Combine(path, fileName);
            var fs       = new FileStream(filePath, FileMode.Create);

            file.CopyTo(fs);
            fs.Close();

            // firma logo path güncelle
            firm.LogoPath = logo;
            await _firmService.UpdateFirmAsync(firm);

            // eski dosyayı sil
            try
            {
                if (System.IO.File.Exists(oldFilepath))
                {
                    System.IO.File.Delete(oldFilepath);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(string.Format("{0} firmasının eski logosu silinemedi. Hata: {1}", firm.Name, e.InnerException));
                return(BadRequest("Eski logo silinemedi"));
            }

            _logger.LogInformation(string.Format("{0} firması logosunu güncelledi.", firm.Name, DateTime.Now));

            return(Ok("Logo güncellendi"));
        }