public IActionResult Post(ProviderModel model) { try { _providerService.AddProvider(ConvertProviderModelToProviderDTO(model)); string currentEmail = this.User.FindFirst(ClaimTypes.Name).Value; string userId = _userHelper.GetUserId(currentEmail); if (userId == null) { return(NotFound("User not found")); } _logger.LogInformation($"[{DateTime.Now.ToString()}]:[provider/post]:[info:add provider]:[user:{userId}]"); return(Ok(model)); } catch (ValidationException ex) { _logger.LogError($"[{DateTime.Now.ToString()}]:[provider/post]:[error:{ex.Property}, {ex.Message}]"); return(BadRequest(ex.Message)); } catch (Exception ex) { _logger.LogError($"[{DateTime.Now.ToString()}]:[provider/post]:[error:{ex}]"); return(BadRequest()); } }
public async Task <IActionResult> Post([FromBody] Provider providerData) { if (ModelState.IsValid) { try { int result = await _providerService.AddProvider(providerData); if (result == 1) { return(Created("CreateProvider", providerData)); } else { return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError)); } } catch (Exception ex) { throw ex; //return BadRequest(new { Message = "Member was already existed." }); //return StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError); } } return(BadRequest(ModelState)); }
public override string Execute() { Console.WriteLine("Trying to register the task provider..."); if (!File.Exists(MetadataFile)) { return($"Could not find \"{MetadataFile}\"."); } var metadataContent = File.ReadAllText(MetadataFile); var provider = DeserializeYaml <NewProviderDto>(metadataContent); if (provider == null) { return("Task provider metadata could not be parsed from the file content."); } var _ = _providerService.AddProvider(provider).Result; var message = $"Task provider {provider.Name} (v{provider.Version}) by {provider.Author} has been registered successfully."; Logger.LogInformation(message); return(message); }
public async Task <ActionResult> PostProvider(Provider provider) { if (provider == null) { return(BadRequest("Provider is invalid!")); } return(Ok(await _providerService.AddProvider(provider))); }
public async Task <ProviderDto> ProviderManagementInsert(ProviderDto requestDto) { var result = await _providerService.AddProvider(requestDto).ConfigureAwait(false); return(new ProviderDto { StatusCode = result != default ? HttpStatusCode.OK : HttpStatusCode.Unauthorized, StatusDescription = result != default ? "Ok" : "Error", });
public ActionResult Create(ProviderVM pr) { Provider prov = new Provider() { ConfirmPassword = pr.ConfirmPassword, DateCreated = pr.DateCreated, Email = pr.Email, Password = pr.Password, Username = pr.Username }; service.AddProvider(prov); return(View()); }
public async Task <IActionResult> Add(IFormFile uploadedFile, [FromForm] AddProviderViewModel model) { if (ModelState.IsValid) { try { ProviderDTO providerDto = null; string path = null; // сохранение картинки if (uploadedFile != null) { path = uploadedFile.FileName; // сохраняем файл в папку files/provider/ в каталоге wwwroot using (var fileStream = new FileStream(_appEnvironment.WebRootPath + _path + path, FileMode.Create)) { await uploadedFile.CopyToAsync(fileStream); _logger.LogInformation($@"{DateTime.Now.ToString()}: Save image {path} in {_path}"); } } providerDto = new ProviderDTO { Email = model.Email, Info = model.Info, IsActive = model.IsActive, IsFavorite = model.IsFavorite, Name = model.Name, Path = path, TimeWorkTo = model.TimeWorkTo, TimeWorkWith = model.TimeWorkWith, WorkingDays = model.WorkingDays }; _providerService.AddProvider(providerDto); string currentUserId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; _logger.LogInformation($"{DateTime.Now.ToString()}: User {currentUserId} added new provider"); return(RedirectToAction("Index")); } catch (ValidationException ex) { ModelState.AddModelError(ex.Property, ex.Message); _logger.LogError($"{DateTime.Now.ToString()}: {ex.Property}, {ex.Message}"); } } return(View(model)); }
public IActionResult EditProvider(EditViewModel model) { if (model.ProviderId != 0) { _providerService.RemoveProvider(model.ProviderId); } else { try { _providerService.AddProvider(model.Name, model.Description, model.Image); } catch (Exception) { ViewData["error"] = "Udbyderen kunne ikke tilføjes"; } } model.Providers = _providerService.GetAllProviders(); return(View(model)); }
public async Task <IActionResult> Create([FromBody] CreateViewModel providerModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await _providerService.AddProvider(providerModel); } catch (DbUpdateException) { return(BadRequest()); } catch (Exception) { return(BadRequest()); } return(Ok()); }
public void Post([FromBody] CreateProviderViewModel provider) { var providerEntity = _mapper.Map <Provider>(provider); _providerService.AddProvider(providerEntity); }
public IActionResult CreateProvider(Provider provider) { _providerService.AddProvider(provider); return(Ok()); }
public void Add(Provider provider) { _providerService.AddProvider(provider); }