예제 #1
0
        public ActionResult Create(MovieModel movie)
        {
            IList <MovieModel> newMovie = new List <MovieModel>();
            var upload = new MovieModel();

            using (var ctx = new IMDBEntities())
            {
                if (movie.ID == 0)
                {
                    upload = new MovieModel
                    {
                        ID            = movie.ID,
                        Name          = movie.Name,
                        Plot          = movie.Plot,
                        ProducerId    = movie.ProducerId,
                        producerName  = movie.producerName,
                        YearOfRelease = movie.YearOfRelease,
                        IsDeleted     = false
                    };
                    if (movie.File != null)
                    {
                        string name         = Path.GetFileName(movie.File.FileName);
                        string relativePath = "~/uploads/" + name;
                        string physicalPath = Server.MapPath(relativePath);
                        movie.File.SaveAs(physicalPath);
                        upload.Poster = name;
                    }
                    else
                    {
                        TempData["ErrorMessage"] = "Try Again";
                        return(RedirectToAction("Index"));
                    }
                    ctx.Movies.Add(Mapper.Map <MovieModel, Movie>(upload));
                    ctx.SaveChanges();
                }
                else
                {
                    if (movie.File != null)
                    {
                        string name         = Path.GetFileName(movie.File.FileName);
                        string relativePath = "~/uploads/" + name;
                        string physicalPath = Server.MapPath(relativePath);
                        movie.File.SaveAs(physicalPath);
                        movie.Poster = name;
                    }
                    var existMovie = ctx.Movies.FirstOrDefault(m => m.ID == movie.ID);
                    existMovie.IsDeleted = false;
                    Mapper.Map(movie, existMovie);
                    ctx.SaveChanges();
                }
            }
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public ActionResult Save(Movy mov)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                using (IMDBEntities dc = new IMDBEntities())
                {
                    if (mov.MovieID > 0)
                    {
                        //Edit
                        var v = dc.Movies.Where(a => a.MovieID == mov.MovieID).FirstOrDefault();
                        if (v != null)
                        {
                            v.MovieName = mov.MovieName;
                            v.Cast      = mov.Cast;
                            v.Director  = mov.Director;
                            v.Producer  = mov.Producer;
                            v.RDate     = mov.RDate;
                        }
                    }
                    else
                    {
                        //Save
                        dc.Movies.Add(mov);
                    }
                    dc.SaveChanges();
                    status = true;
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
 public void AddBook(string t, int id)
 {
     using (var entities = new IMDBEntities())
     {
         Basket b = _mapper.Map<Basket>(basket);
         entities.Basket.AddBook(t,id);
         entities.SaveChanges();
     }
     }
        public BasketDTO CreateBasket(BasketDTO basket)
        {
            using (var entities = new IMDBEntities())
            {
                Basket b = _mapper.Map<Basket>(basket);
                entities.Basket.Add(b);
                entities.SaveChanges();

                return _mapper.Map<BasketDTO>(b);
            }
        }
        public ActionResult Delete(int id)
        {
            using (var ctx = new IMDBEntities())
            {
                var existRecord = ctx.Producers.FirstOrDefault(p => p.ID == id);
                if (existRecord != null)
                {
                    existRecord.IsDeleted = true;
                    ctx.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
예제 #6
0
        public ActionResult Delete(int id)
        {
            using (var ctx = new IMDBEntities())
            {
                var existRecord = ctx.Movies.Single(m => m.ID == id);
                if (existRecord != null)
                {
                    existRecord.IsDeleted = true;
                    ctx.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
        public void DeleteBasket(int id)
        {
            using (var entities = new IMDBEntities())
            {
                var b = entities.Baskets.SingleOrDefault(bb => bb.BasketID == id);

                if (b == null)
                {
                    return;
                }

                entities.Baskets.Remove(b);
                entities.SaveChanges();
            }
        }
 public List <BooksDTO> Find(string text, string category)
 {
     using (var entities = new IMDBEntities())
     {
         var bookInDB = entities.Books.SingleOrDefault(b => b.Title == text && b.Category == category);
         if (bookInDB == null)
         {
             entities.Books.Add(bookInDB);
         }
         else
         {
             _mapper.Map(bookInDB);
         }
         entities.SaveChanges();
         return(_mapper.Map <BooksDTO>(bookInDB));
     }
 }
 public void UpdateBasket(int id,int Sid)
 {
     using (var entities = new IMDBEntities())
     {
         var basketInDB = entities.Baskets.SingleOrDefault(b => b.ID == id);
         if (basketInDB == null)
         {        
             entities.Baskets.Add(basketInDB);
         }
         else
         {
             _mapper.Map(basketInDB);
         }
         entities.SaveChanges();
         //return _mapper.Map<BasketDTO>(basketInDB);
     }
 }
예제 #10
0
        public ActionResult DeleteMovie(int id)
        {
            bool status = false;

            using (IMDBEntities dc = new IMDBEntities())
            {
                var v = dc.Movies.Where(a => a.MovieID == id).FirstOrDefault();
                if (v != null)
                {
                    dc.Movies.Remove(v);
                    dc.SaveChanges();
                    status = true;
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
예제 #11
0
 public ActionResult Create(ProducerModel producer)
 {
     using (var ctx = new IMDBEntities())
     {
         if (producer.ID == 0)
         {
             var newProducer = ctx.Producers.Add(Mapper.Map <ProducerModel, Producer>(producer));
             newProducer.IsDeleted = false;
         }
         else
         {
             var existProducer = ctx.Producers.FirstOrDefault(p => p.ID == producer.ID);
             if (existProducer != null)
             {
                 existProducer.IsDeleted = false;
                 Mapper.Map(producer, existProducer);
             }
         }
         ctx.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
예제 #12
0
 public ActionResult Create(ActorModel actor)
 {
     using (var ctx = new IMDBEntities())
     {
         if (actor.ID == 0)
         {
             var newActor = ctx.Actors.Add(Mapper.Map <ActorModel, Actor>(actor));
             newActor.IsDeleted = false;
         }
         else
         {
             var existActor = ctx.Producers.FirstOrDefault(p => p.ID == actor.ID);
             if (existActor != null)
             {
                 existActor.IsDeleted = false;
                 Mapper.Map(actor, existActor);
             }
         }
         ctx.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }