Exemple #1
0
        public async Task <IActionResult> Create(CreateProviderModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            await _providerService.CreateAsync(model.OwnerEmail);

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public async Task <IActionResult> Create(ProviderPostRequest model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception("Petición de alta inválida");
                }

                return(Ok(await _providerService.CreateAsync(model, _apiDbContext)));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        public async Task <IActionResult> CreateProvider(NewProviderDto provider)
        {
            try
            {
                if (provider.Location == provider.Name)
                {
                    ModelState.AddModelError(
                        "Location",
                        "The provider description should be different from rhe name!");
                }

                if (await _providerService.ProvidersExistsAsync(provider.Name))
                {
                    ModelState.AddModelError(
                        "Name",
                        "A provider with the same name already exists into the database!");
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var insertedProvider = await _providerService.CreateAsync(provider);

                if (insertedProvider == null)
                {
                    return(Problem());
                }

                return(CreatedAtRoute("GetProvider", new { id = insertedProvider.Id }, insertedProvider));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to succeed the operation!"));
            }
        }