Exemplo n.º 1
0
        /// <summary>
        /// Create a new Institution
        /// </summary>
        /// <param name="requestDTO">Request payload</param>
        /// <returns></returns>
        public async Task <IActionResult> CreateNewInstitution([FromBody] InstitutionRequestDTO requestDTO)
        {
            var result = await _institutionService.CreateAsync(requestDTO);

            if (result != null)
            {
                await DeleteCache("getAllInstitution", cacheName);
            }
            return(new OkObjectResult(new { result }));
        }
        public async Task <IActionResult> Post([FromBody] NewInstitutionDto institution)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _institutionService.CreateAsync(institution);

            if (result is null)
            {
                return(BadRequest());
            }

            return(CreatedAtAction("Get", new { id = result.Id }, result));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddInstitution(AddInstitutionViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var institution = new Institution()
            {
                Name        = viewModel.Name,
                Description = viewModel.Description
            };

            var result = await InstitutionService.CreateAsync(institution);

            if (result == false)
            {
                ModelState.AddModelError("", "Nie można dodać nowej instytucji");
                return(View(viewModel));
            }

            return(RedirectToAction("ShowInstitution", "Admin"));
        }