public async Task <ActionResult> CreateOrUpdateAsync(string offerName, string planName, [FromBody] Plan plan) { AADAuthHelper.VerifyUserAccess(this.HttpContext, _logger, true); if (plan == null) { throw new LunaBadRequestUserException(LoggingUtils.ComposePayloadNotProvidedErrorMessage(nameof(plan)), UserErrorCode.PayloadNotProvided); } if (!planName.Equals(plan.PlanName)) { throw new LunaBadRequestUserException(LoggingUtils.ComposeNameMismatchErrorMessage(typeof(Plan).Name), UserErrorCode.NameMismatch); } if (await _planService.ExistsAsync(offerName, planName)) { _logger.LogInformation($"Update plan {planName} in offer {offerName} with payload {JsonSerializer.Serialize(plan)}."); await _planService.UpdateAsync(offerName, planName, plan); return(Ok(plan)); } else { _logger.LogInformation($"Create plan {planName} in offer {offerName} with payload {JsonSerializer.Serialize(plan)}."); await _planService.CreateAsync(offerName, plan); return(CreatedAtRoute(nameof(GetAsync) + nameof(Plan), new { offerName = offerName, planName = plan.PlanName }, plan)); } }
public async Task <IActionResult> Add(AddPlanViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await _userManager.GetUserAsync(User); if (user == null) { ModelState.AddModelError("", "Błąd dodawania planu"); return(View(model)); } var plan = new Plan() { Name = model.Name, Description = model.Description, Created = DateTime.Now, User = user }; var result = await _planService.CreateAsync(plan); if (result == false) { ModelState.AddModelError("", "Błąd dodawania planu"); return(View(model)); } return(RedirectToAction("List", "Plan")); }
public async Task <IActionResult> Post([FromBody] Plan data) { data.TenantId = Context.TenantId; return(Respond(await _service.CreateAsync(data))); }