public async Task <IActionResult> Create(CreateJobInputModel input, [FromServices] IBaseService _baseService) { var user = await _userManager.GetUserAsync(User); if (user == null) { return(Redirect("/Identity/Account/Errors/AccessDenied")); } input.AllLocations = _locationService.GetAllSelectList(); input.AllCategories = _categoriesService.GetAllSelectList(); if (!ModelState.IsValid) { return(View(input)); } input.isArchived = false; var result = await _jobsService.Create(input, user); if (result.Success) { _baseService.ToastNotify(ToastMessageState.Warning, "Внимание", "Моля изчакайте заявката ви да се прегледа от администратор.", 7000); _baseService.ToastNotify(ToastMessageState.Success, "Успешно", "Обявата ви е добавена.", 5000); return(Redirect($"/identity/Jobs/Index")); } return(this.View(input)); }
public HttpResponseMessage Create(JobRequest req) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } var id = jobs.Create(req); return(Request.CreateResponse(HttpStatusCode.Created, id)); }
public async Task <IActionResult> Create([FromBody] Job model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var job = await _service.Create(model); return(CreatedAtRoute("GetJob", new { id = job.Id }, job)); }
public async Task <JobDto> ExecuteProcess(IFormFile formFile) { var guid = Guid.NewGuid(); var job = _jobsService.Create(formFile.FileName, guid); await _cloudStorageService.Upload(formFile, guid); await _queueService.Publish(job); return(_jobsService.UpdateStatusQueued(job)); }
public void Create_ShouldInvokeJobsRepositoryCreateOnce() { // Arrange const string fileName = "file"; var guid = Guid.Empty; // Act _jobsService.Create(fileName, guid); // Assert _jobsRepositoryMock.Verify(v => v.Create(It.Is <JobDto>(x => x.JobStatus == EnumUtility.GetValue(JobStatus.Created) && x.JobId == guid && x.FileName == fileName)), Times.Once); }
public async Task <ActionResult> Create(CreateJobRequestModel model) { var jobId = await _service.Create(model.Description, model.ImageUrl, _currentUserService.GetId()); return(Created(nameof(Create), jobId)); }
public async Task <IActionResult> Wizard(WizardViewModel model) { model.Categories = _categoriesService.GetAll(); model.JobTypes = _hiretypesService.GetAll(); model.Companies = _companiesService.GetByUserId(_currentUser.UserId); if (ModelState.IsValid) { try { var companyId = model.CompanyId; if (model.CreateNewCompany) { var company = new Company { Name = model.CompanyName, Url = model.CompanyUrl, LogoUrl = model.CompanyLogoUrl, UserId = _currentUser.UserId, Email = model.CompanyEmail }; if (string.IsNullOrWhiteSpace(company.LogoUrl) || !company.LogoUrl.StartsWith("https") || (!company.LogoUrl.EndsWith(".jpg") && !company.LogoUrl.EndsWith(".jpeg") && !company.LogoUrl.EndsWith(".png"))) { company.LogoUrl = $"{this.Request.Scheme}://{this.Request.Host}{Constants.DefaultLogoUrl}"; } _companiesService.Create(company); companyId = company.Id; } if (model.Id.HasValue) { var originalJob = _jobsService.GetById(model.Id.Value); if (originalJob.UserId == _currentUser.UserId) { originalJob.CategoryId = model.CategoryId; originalJob.HireTypeId = model.JobTypeId; originalJob.CompanyId = companyId.Value; originalJob.HowToApply = model.HowToApply; originalJob.Description = model.Description; originalJob.Title = model.Title; originalJob.IsRemote = model.IsRemote; originalJob.IsApproved = false; if (originalJob.Location.PlaceId != model.LocationPlaceId) { originalJob.Location = new Location { PlaceId = model.LocationPlaceId, Name = model.LocationName, Longitude = model.LocationLongitude, Latitude = model.LocationLatitude }; } var result = _jobsService.Update(originalJob); if (result.Success) { try { await _slackService.PostJob(originalJob, Url); } catch (Exception ex) { HttpContext.RiseError(ex); } return(RedirectToAction("Wizard", new { Id = model.Id.Value }).WithSuccess("Posición editada exitosamente")); } return(View(model).WithError(result.Messages)); } else { return(RedirectToAction("Index", "Home").WithError("No tienes permiso para editar esta posición")); } } else { var newJob = new Job { CategoryId = model.CategoryId, HireTypeId = model.JobTypeId, CompanyId = companyId.Value, HowToApply = model.HowToApply, Description = model.Description, Title = model.Title, IsRemote = model.IsRemote, Location = new Location { PlaceId = model.LocationPlaceId, Name = model.LocationName, Longitude = model.LocationLongitude, Latitude = model.LocationLatitude }, UserId = _currentUser.UserId, IsHidden = false, IsApproved = false, PublishedDate = DateTime.Now }; var result = _jobsService.Create(newJob); if (result.Success) { try { await _slackService.PostJob(newJob, Url).ConfigureAwait(false); } catch (Exception ex) { HttpContext.RiseError(ex); } return(RedirectToAction("Details", new { newJob.Id, isPreview = true }).WithInfo(result.Messages)); } throw new Exception(result.Messages); } } catch (Exception ex) { HttpContext.RiseError(ex); return(View(model).WithError(ex.Message)); } } return(View(model)); }