// GET: Casts/Details/5 public ActionResult Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CastViewModel cast = Mapper.Map <CastViewModel>(castService.Get(id.Value)); if (cast == null) { return(HttpNotFound()); } return(View(cast)); }
public ActionResult Details() { CastViewModel model = new CastViewModel(); List <CastViewModel> movieList = new List <CastViewModel>(); dynamic movieCollect = JsonConvert.DeserializeObject <RootObject>(SearchMovie("31").Result); foreach (var movie in movieCollect) { movieList.Add(movie); } return(View(movieList)); }
// GET: Casts/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CastViewModel cast = Mapper.Map <CastViewModel>(castService.Get(id.Value)); if (cast == null) { return(HttpNotFound()); } ViewBag.FilmId = new SelectList(filmService.GetAll(), "Id", "Name", cast.FilmId); ViewBag.TvSerieId = new SelectList(tvSerieService.GetAll(), "Id", "Name", cast.TvSerieId); return(View(cast)); }
public IHttpActionResult Put(CastViewModel bp) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } using (var ctx = new EMSEntities()) { try { var existingBp = ctx.CSTs.Where(s => s.TRNNO == bp.TRNNO) .FirstOrDefault <CST>(); if (existingBp != null) { existingBp.CDESC = bp.CDESC; existingBp.STATUS = bp.STATUS; ctx.SaveChanges(); } else { return(NotFound()); } } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } } return(Ok()); }
public IHttpActionResult PostNewCast(CastViewModel cst) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } using (var ctx = new EMSEntities()) { int totalConunt = ctx.CSTs.Count <CST>(); cst.TRNNO = totalConunt + 1; ctx.CSTs.Add(new CST() { TRNNO = (cst.TRNNO), CDESC = cst.CDESC, STATUS = cst.STATUS }); try { ctx.SaveChanges(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } } return(Ok()); }
public string GetShows(int pageNumber) { //start scrapping Scrapper scrapper = new Scrapper(); Task result = scrapper.Scrape(pageNumber); List <ShowViewModel> shows = new List <ShowViewModel>(); if (result.IsCompleted) { using (var db = new MovieContext()) { var tvshows = db.Shows.Where(p => p.PageNumber == pageNumber).ToList(); foreach (var item in tvshows) { var show = new ShowViewModel { Id = item.Id, Name = item.Name }; show.Cast = new List <CastViewModel>(); var casts = db.Casts.Where(p => p.ShowId == item.Id).OrderByDescending(p => p.Birthday); foreach (var castItem in casts) { var model = new CastViewModel { Id = castItem.Id, Birthday = castItem.Birthday, Name = castItem.Name }; show.Cast.Add(model); } shows.Add(show); } } } return(JsonConvert.SerializeObject(shows)); }
public IHttpActionResult GetCastById(int id) { CastViewModel cst = null; using (var ctx = new EMSEntities()) { cst = ctx.CSTs .Where(s => s.TRNNO == id) .Select(s => new CastViewModel() { TRNNO = s.TRNNO, CDESC = s.CDESC, STATUS = s.STATUS }).FirstOrDefault <CastViewModel>(); } if (cst == null) { return(NotFound()); } return(Ok(cst)); }