Beispiel #1
0
        public ActionResult Create([Bind(Include = "MovieID,Name,SmallPictureUrl,LargePictureUrl,HasReleased,LanguageID")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _db.Movies.Add(movie);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.LanguageID = new SelectList(_db.Languages, "LanguageID", "LanguageName", movie.LanguageID);
            return(View(movie));
        }
Beispiel #2
0
        public void CreateNewDb()
        {
            foreach (var language in LangaugeCreator.GetAll())
            {
                _db.Languages.Add(language);
            }
            foreach (var sites in WebSiteCreator.GetAllCriticSites())
            {
                _db.CriticSites.Add(sites);
            }
            foreach (var movie in MovieCreator.CreateMovies())
            {
                _db.Movies.Add(movie);
            }
            foreach (var movieDetail in MovieDetailCreator.CreateMovies())
            {
                _db.MovieDetails.Add(movieDetail);
            }

            foreach (var criticRating in CriticRatingCreator.CreateCriticRatings())
            {
                _db.CriticRatings.Add(criticRating);
            }

            foreach (var userRating in UserRatingCreator.CreateUserRating())
            {
                _db.UserRatings.Add(userRating);
            }

            _db.SaveChanges();
        }
 public void InsertOrUpdateEntity(int id, TEntityDTO entityDTO)
 {
     using (var dbContext = new ProjectManhattanEntities())
     {
         var entity = dbContext.Set <TEntity>().Find(id);
         if (entity != null)
         {
             Mapper.Map(entityDTO, entity);
             dbContext.SaveChanges();
         }
         else
         {
             var newEntity = Mapper.Map <TEntity>(entityDTO);
             dbContext.Set <TEntity>().Add(newEntity);
             dbContext.SaveChanges();
             Mapper.Map(newEntity, entityDTO);
         }
     }
 }
 public int InsertOrUpdateUser(UserDTO entityDTO)
 {
     using (var dbContext = new ProjectManhattanEntities())
     {
         var entity = dbContext.Set <User>().Find(entityDTO.UserId);
         if (entity != null)
         {
             Mapper.Map(entityDTO, entity);
             dbContext.SaveChanges();
             return(entity.UserId);
         }
         else
         {
             var newEntity = Mapper.Map <User>(entityDTO);
             dbContext.Set <User>().Add(newEntity);
             dbContext.SaveChanges();
             return(newEntity.UserId);
         }
     }
 }
 public void DeleteEntity(int id)
 {
     using (var dbContext = new ProjectManhattanEntities())
     {
         var entity = dbContext.Set <TEntity>().Find(id);
         if (entity != null)
         {
             dbContext.Set <TEntity>().Remove(entity);
             dbContext.SaveChanges();
         }
     }
 }