public async Task <string> CreatedAsync(CreateUriModel model) { var validationResult = await this.CreateModelValidator.ValidateAsync(model); if (validationResult.IsValid == false) { return(string.Join("\n", validationResult.Errors)); } if (await this.IsSlugFreeAsync(model.Slug) == false) { return($"{model.Slug} is already in use."); } var uri = new Uri { Link = model.Link, Slug = model.Slug }; await this.Context.Uris.AddAsync(uri); await this.Context.SaveChangesAsync(); return("Successfully created."); }
public async Task <IActionResult> Create(CreateUriModel model) { if (model.Link == null || model.Slug == null) { return(View("Error", "The input is empty!")); } try { var opertaion = await this._uriService.CreatedAsync(model).ConfigureAwait(false); if (opertaion != "Successfully created.") { return(View("Error", opertaion)); } return(View("Index")); } catch (Exception e) { return(View("Error", e.Message)); } }