public async Task <IActionResult> Details(int id) { ActorVM actor; var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:55169/api/Actors/" + id); request.Headers.Add("Accept", "application/json"); var client = _httpClientFactory.CreateClient(); var response = await client.SendAsync(request).ConfigureAwait(false); if (response.IsSuccessStatusCode) { using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); actor = await JsonSerializer.DeserializeAsync <ActorVM>(responseStream); } else { actor = new ActorVM(); } return(View(actor)); }
public async Task <IActionResult> Create(ActorVM actor) { if (ModelState.IsValid) { var client = _httpClientFactory.CreateClient("MMDB_API"); string uniqueFileName = UploadedFile(actor); ActorPutVM actorPost = new ActorPutVM { Name = actor.Name, DateOfBirth = actor.DateOfBirth, gender = actor.gender, Avatar = uniqueFileName }; var actorContent = new StringContent(JsonSerializer.Serialize(actorPost), Encoding.UTF8, "application/json"); var response = await client.PostAsync("actors", actorContent).ConfigureAwait(false); if (response.IsSuccessStatusCode) { return(RedirectToAction(nameof(Index))); } return(RedirectOnError(response, "Create", "create an actor", "creating an actor")); } return(View(actor)); }
public ActionResult UpdateActor(int id) { ActorVM avm = new ActorVM { Actor = _acRep.Find(id), }; return(View(avm)); }
public ActionResult ActorList() { ActorVM avm = new ActorVM { Actors = _acRep.GetActives(), }; return(View(avm)); }
public ActionResult AddActor() { ActorVM avm = new ActorVM { Actor = new Actor(), Movies = _mRep.GetActives(), }; return(View(avm)); }
public ActionResult UpdateActor(ActorVM item) { Actor toBeUpdated = _acRep.FirstOrDefault(x => x.ID == item.Actor.ID); toBeUpdated.FirstName = item.Actor.FirstName; toBeUpdated.LastName = item.Actor.LastName; toBeUpdated.Age = item.Actor.Age; toBeUpdated.Country = item.Actor.Country; _acRep.Update(toBeUpdated); return(RedirectToAction("ActorList")); }
private string UploadedFile(ActorVM actor) { string uniqueFileName = null; if (actor.AvatarFile != null) { string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images/Avatars"); uniqueFileName = Guid.NewGuid().ToString() + "_" + actor.AvatarFile.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { actor.AvatarFile.CopyTo(fileStream); } } return(uniqueFileName); }
public async Task <IActionResult> Delete(int id, IFormCollection collection) { var client = _httpClientFactory.CreateClient("MMDB_API"); var response = await client.GetAsync("actors/" + id).ConfigureAwait(false); if (response.IsSuccessStatusCode) { using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); ActorVM actor = await JsonSerializer.DeserializeAsync <ActorVM>(responseStream); return(View(actor)); } return(RedirectOnError(response, "Delete", "delete an actor", "getting the actor details")); }
public ActorVM Insert(ActorInsertRequest request) { ActorVM viewModel = new ActorVM(); if (request == null) { return(viewModel); } Actors actor = new Actors(); actor.Name = request.Name; actor.Age = request.Age; _context.Actors.Add(actor); _context.SaveChanges(); return(_mapper.Map <ActorVM>(actor)); }