public async Task <IActionResult> Create(ActorCreateInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var exists = this.actorsService.CheckifExists(input.FirstName, input.LastName); if (exists) { this.TempData["ExistingActorTemp"] = "Actor with the same name already exists in the database."; return(this.View(input)); } var actor = await this.actorsService.CreateActorAsync(new CreateActorViewModel { Image = input.Image, Info = input.Info, FirstName = input.FirstName, LastName = input.LastName, BirthDate = input.BirthDate, Gender = input.Gender.ToString(), }); this.TempData["CreateActorTemp"] = "You have added a new actor to the database."; return(this.RedirectToAction(nameof(this.Details), new { id = actor })); }
public async Task <IActionResult> Create([FromBody] ActorCreateInputModel inputModel) { if (inputModel == null) { return(BadRequest()); } var entity = new Actor { Name = inputModel.Name }; this.context.Actors.Add(entity); await this.context.SaveChangesAsync(); var outputModel = new { entity.Id, entity.Name }; return(CreatedAtRoute("GetActor", new { id = outputModel.Id }, outputModel)); }