Example #1
0
 public static void Delete(Movie item)
 {
     try
     {
         var items = GetAll();
         var itemToDelete = items.Where(p => p.Id == item.Id).FirstOrDefault();
         items.Remove(itemToDelete);
         Add(items);
     }
     catch { }
 }
Example #2
0
        public static void Add(Movie item)
        {
            try
            {
                var items = GetAll();

                if (items.Any(p => p.Id == item.Id || p.Title == item.Title))
                    return;

                items.Add(item);
                Add(items);
            }
            catch { }
        }
Example #3
0
        public ActionResult Create(HnJ.Helper.Models.Movie movie, HttpPostedFileBase poster)
        {
            if (ModelState.IsValid)
            {
                if (movie.Id != Guid.Empty) // Update
                {
                    if (poster != null && poster.ContentLength > 0)
                    {
                        string guid = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(poster.FileName);

                        var filePath = System.IO.Path.Combine(Server.MapPath("~/Content/Posters/"), guid);

                        poster.SaveAs(filePath);

                        movie.PosterName = guid;
                    }
                    else
                    {
                        var movieToUpdate = Movies.Get(movie.Id);

                        movie.PosterName = movieToUpdate.PosterName;
                    }

                    Movies.Update(movie);

                    return(RedirectToAction("Create", new { @id = movie.Id }));
                }
                else
                {
                    if (poster != null && poster.ContentLength > 0)
                    {
                        string guid = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(poster.FileName);

                        var filePath = System.IO.Path.Combine(Server.MapPath("~/Content/Posters/"), guid);

                        poster.SaveAs(filePath);

                        movie.Id         = Guid.NewGuid();
                        movie.PosterName = guid;

                        Movies.Add(movie);

                        return(RedirectToAction("Create", new { @id = movie.Id }));
                    }
                }
            }

            return(RedirectToAction("Create"));
        }
Example #4
0
        public ActionResult Create(Guid? id)
        {
            var item = new Movie();
            ViewBag.Mode = "Add New";
            ViewBag.IsEditMode = false;

            if (id.HasValue && id.Value != Guid.Empty)
            {
                item = Helper.Movies.Get(id.Value);
                ViewBag.Mode = "Edit";
                ViewBag.IsEditMode = true;
            }

            return View(item);
        }
Example #5
0
        public static void Update(Movie item)
        {
            try
            {
                var items = GetAll();

                var oldItem = items.Where(p => p.Id == item.Id).FirstOrDefault();

                items.Remove(oldItem);
                items.Add(item);

                Add(items);
            }
            catch { }
        }