示例#1
0
        //Insert the genre into the db, and generate a new Id for it.
        public int Insert()
        {
            try
            {
                using (MusicEntities dc = new MusicEntities())
                {
                    //Create a new Id
                    this.Id = Guid.NewGuid();

                    //Set the properties
                    tblGenre genre = new tblGenre
                    {
                        Id          = this.Id,
                        Description = this.Description
                    };

                    //Add it to the table and save changes
                    dc.tblGenres.Add(genre);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
        public static int Delete(int id)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    //get the row i want to delete
                    tblGenre deleteRow = (from dt in dc.tblGenres
                                          where dt.Id == id
                                          select dt).FirstOrDefault();

                    if (deleteRow != null)
                    {
                        dc.tblGenres.Remove(deleteRow);
                        return(dc.SaveChanges());
                    }
                    else
                    {
                        throw new Exception("Row not found");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#3
0
        public ActionResult FilterPostsByGenresID(int?id, int?page)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }
            tblGenre genre = db.tblGenres.Find(id);

            if (db.tblTags.FirstOrDefault(t => t.Tag_Title.Contains(genre.Genres_Name)) != null)
            {
                db.tblTags.FirstOrDefault(t => t.Tag_Title.Contains(genre.Genres_Name)).Tag_CountSearch++;
                db.SaveChanges();
            }
            else
            {
                tblTag tag = new tblTag()
                {
                    Tag_Title       = genre.Genres_Name,
                    Tag_DateAdd     = DateTime.Now,
                    Tag_CountSearch = 1
                };
                db.tblTags.Add(tag);
                db.SaveChanges();
            }
            ViewBag.Title     = "Tìm kiếm code theo thể loại";
            ViewBag.countPost = db.tblPosts.Where(t => t.Post_Genres == id && t.Post_Active == true && t.Post_Trash == false).Count();
            IPagedList <tblPost> post = db.tblPosts.Where(t => t.Post_Genres == id && t.Post_Active == true && t.Post_Trash == false).OrderByDescending(t => t.Post_DateCreate).ToPagedList(page ?? 1, PAGE_SIZE);

            return(View("Index", post));
        }
示例#4
0
        public static bool Insert(Genre genre)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    // Make a new row
                    tblGenre newrow = new tblGenre();

                    // Set the properties
                    // Ternary Operator condition ? true : false
                    newrow.Id          = dc.tblGenres.Any() ? dc.tblGenres.Max(p => p.Id) + 1 : 1; // If there are any rows, get the max id and add 1, if not use 1
                    newrow.Description = genre.Description;


                    // Do the Insert
                    dc.tblGenres.Add(newrow);

                    // Commit the insert
                    dc.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#5
0
        public static int Update(Genre genre)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    //get the row i want to update
                    tblGenre updateRow = (from dt in dc.tblGenres
                                          where dt.Id == genre.Id
                                          select dt).FirstOrDefault();

                    if (updateRow != null)
                    {
                        updateRow.Description = genre.Description;
                        return(dc.SaveChanges());
                    }
                    else
                    {
                        throw new Exception("Row not found");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#6
0
        public static int Update(Genre genre)
        {
            using (DVDCentralEntities dc = new DVDCentralEntities())
            {
                try
                {
                    tblGenre updatedrow = dc.tblGenres.Where(dt => dt.Id == genre.Id).FirstOrDefault();

                    // Check to see if object exists
                    if (genre != null)
                    {
                        // Update the proper fields
                        updatedrow.Description = genre.Description;


                        // Save and commit changes
                        return(dc.SaveChanges());
                    }
                    else
                    {
                        // throw an exception stating the row was not found
                        throw new Exception("Row was not found.");
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
示例#7
0
        public static int Delete(int id)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblGenre deleterow = dc.tblGenres.FirstOrDefault(dt => dt.Id == id);

                    if (deleterow != null)
                    {
                        // Remove the row
                        dc.tblGenres.Remove(deleterow);

                        // Commit/Save the changes
                        return(dc.SaveChanges());
                    }
                    else
                    {
                        throw new Exception("Row was not found.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#8
0
        public static int Insert(Genre genre)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblGenre tblGenre = new tblGenre();

                    tblGenre.Description = genre.Description;

                    //example of ternary operator
                    tblGenre.Id = dc.tblGenres.Any() ? dc.tblGenres.Max(dt => dt.Id) + 1 : 1;

                    //Change the ID of the inserted Student
                    genre.Id = tblGenre.Id;

                    dc.tblGenres.Add(tblGenre);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#9
0
        public void LoadById()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    //Make sure that the ID is set and valid
                    if (this.Id >= 0)
                    {
                        tblGenre genre = dc.tblGenres.FirstOrDefault(g => g.Id == this.Id);

                        //Make sure that a genre was retrieved
                        if (genre != null)
                        {
                            //Set the properties on this genre
                            this.Description = genre.Description;
                        }
                        else
                        {
                            throw new Exception("No genre to load with this Id");
                        }
                    }
                    else
                    {
                        throw new Exception("Genre Id not Valid");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#10
0
        public static Genre LoadById(int id)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblGenre row = (from dt in dc.tblGenres
                                    where dt.Id == id
                                    select dt).FirstOrDefault();

                    if (row != null)
                    {
                        return new Genre {
                                   Id = row.Id, Description = row.Description
                        }
                    }
                    ;
                    else
                    {
                        throw new Exception("Row was not found");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#11
0
        public ActionResult DeleteConfirmed(int id)
        {
            tblGenre tblGenre = db.tblGenres.Find(id);

            db.tblGenres.Remove(tblGenre);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#12
0
 public ActionResult Edit([Bind(Include = "Genres_ID,Genres_Name")] tblGenre tblGenre)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tblGenre).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tblGenre));
 }
示例#13
0
        public ActionResult Create([Bind(Include = "Genres_ID,Genres_Name")] tblGenre tblGenre)
        {
            if (ModelState.IsValid)
            {
                db.tblGenres.Add(tblGenre);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tblGenre));
        }
示例#14
0
        public void Delete()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblGenre genre = dc.tblGenres.FirstOrDefault(g => g.Id == -99);
                dc.tblGenres.Remove(genre);
                int rowsEffected = dc.SaveChanges();

                Assert.IsTrue(rowsEffected == 1);
            }
        }
示例#15
0
 public ActionResult Edit([Bind(Include = "GenreID, GenreName, GenreBio, ImageSrc, ImageAlt")] tblGenre genre)
 {
     if (ModelState.IsValid)
     {
         context.Entry(genre).State = EntityState.Modified;
         context.SaveChanges();
         return(RedirectToAction("AdminIndex"));
     }
     else
     {
         return(View());
     }
 }
示例#16
0
        public void Update()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblGenre genre = dc.tblGenres.FirstOrDefault(g => g.Id == -99);
                genre.Description = "UpdateGenre";

                //Save changed property
                dc.SaveChanges();

                tblGenre updatedGenre = dc.tblGenres.FirstOrDefault(g => g.Description == "UpdateGenre");
                Assert.AreEqual(genre.Id, updatedGenre.Id);
            }
        }
示例#17
0
        // GET: Admin/tblGenresAdmin/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tblGenre tblGenre = db.tblGenres.Find(id);

            if (tblGenre == null)
            {
                return(HttpNotFound());
            }
            return(View(tblGenre));
        }
示例#18
0
        public void DeleteTest()
        {
            using (DVDCentralEntities dc = new DVDCentralEntities())
            {
                tblGenre row = (from dt in dc.tblGenres
                                where dt.Id == -99
                                select dt).FirstOrDefault();

                dc.tblGenres.Remove(row);


                int results = dc.SaveChanges();

                Assert.AreNotEqual(0, results);
            }
        }
示例#19
0
        public void InsertTest()
        {
            using (DVDCentralEntities dc = new DVDCentralEntities())
            {
                tblGenre newrow = new tblGenre();

                newrow.Id          = -99;
                newrow.Description = "Children's Cartoon";

                dc.tblGenres.Add(newrow);

                int results = dc.SaveChanges();

                Assert.IsTrue(results == 1);
            }
        }
示例#20
0
        public void InsertTest()
        {
            tblGenre newrow = new tblGenre();

            // Set the column values
            newrow.Id          = -99;
            newrow.Description = "My new Genre";

            // Insert of the row
            dc.tblGenres.Add(newrow);

            // Commit the changes (insert a row) and then return the rows affected.
            int rowsaffected = dc.SaveChanges();

            Assert.AreNotEqual(0, rowsaffected);
        }
示例#21
0
        //Retrieve the genre from the database with this Id
        public void LoadById()
        {
            try
            {
                using (MusicEntities dc = new MusicEntities())
                {
                    //Retrieve from the db
                    tblGenre genre = dc.tblGenres.FirstOrDefault(g => g.Id == this.Id);

                    //Set this genre's properties
                    this.Description = genre.Description;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#22
0
 public static int Delete(int id)
 {
     try
     {
         using (DVDCentralEntities dc = new DVDCentralEntities())
         {
             tblGenre deleterow = (from dt in dc.tblGenres
                                   where dt.Id == id
                                   select dt).FirstOrDefault();
             dc.tblGenres.Remove(deleterow);
             return(dc.SaveChanges());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#23
0
        public static int Update(int id, string description)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblGenre updaterow = (from dt in dc.tblGenres
                                          where dt.Id == id
                                          select dt).FirstOrDefault();
                    updaterow.Description = description;

                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#24
0
        public int Update()
        {
            try
            {
                using (MusicEntities dc = new MusicEntities())
                {
                    //Retrieve the record from the DB
                    tblGenre genre = dc.tblGenres.FirstOrDefault(g => g.Id == this.Id);

                    //Update the properties
                    genre.Description = this.Description;

                    //Save the changes
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#25
0
        public void Insert()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                //Create a genre
                tblGenre genre = new tblGenre
                {
                    Id          = -99,
                    Description = "TestGenre"
                };

                //Insert the row
                dc.tblGenres.Add(genre);

                //Commit the changes
                int rowsInserted = dc.SaveChanges();

                //Make sure that one row was inserted
                Assert.IsTrue(rowsInserted == 1);
            }
        }
示例#26
0
        public ActionResult Create(CreateViewModel createvm)
        {
            if (ModelState.IsValid)
            {
                string filename = Path.GetFileName(createvm.Image.FileName);
                createvm.ImageSrc = "~/Content/GenreImages/" + filename;
                filename          = Path.Combine(Server.MapPath("~/Content/GenreImages/"), filename);
                createvm.Image.SaveAs(filename);

                tblGenre genre = new tblGenre(createvm.GenreName, createvm.GenreBio, createvm.ImageSrc, createvm.ImageAlt);
                context.tblGenres.Add(genre);
                context.SaveChanges();
                ModelState.Clear();

                return(RedirectToAction("AdminIndex"));
            }
            else
            {
                return(View());
            }
        }
示例#27
0
        public int Delete()
        {
            try
            {
                using (MusicEntities dc = new MusicEntities())
                {
                    //Retrieve it from the DB
                    tblGenre genre = dc.tblGenres.FirstOrDefault(g => g.Id == this.Id);

                    //Remove the genre
                    dc.tblGenres.Remove(genre);

                    //Save the changes
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#28
0
        public int Insert()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    tblGenre genre = new tblGenre
                    {
                        Description = this.Description,
                        Id          = dc.tblGenres.Any() ? dc.tblGenres.Max(g => g.Id) + 1 : 1
                    };
                    this.Id = genre.Id;
                    dc.tblGenres.Add(genre);

                    //Return the rows effected
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#29
0
        public ActionResult Delete(DeleteViewModel view)
        {
            bool isPasswordValid = context.tblUsers
                                   .Any(x => x.UserName.ToLower() == User.Identity.Name.ToLower() &&
                                        x.Password == view.Password);

            if (isPasswordValid)
            {
                tblGenre genre = context.tblGenres.Find(view.Genre.GenreID);

                List <tblRecord> records = context.tblRecords.Where(x => x.ArtistID == genre.GenreID).ToList();
                foreach (var item in records)
                {
                    context.tblRecords.Remove(item);
                }

                context.tblGenres.Remove(genre);
                context.SaveChanges();
                return(RedirectToAction("AdminIndex"));
            }

            return(View());
        }
示例#30
0
        public static int Insert(out int id, string description)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblGenre newrow = new tblGenre();

                    newrow.Description = description;

                    newrow.Id = dc.tblGenres.Any() ? dc.tblGenres.Max(dt => dt.Id) + 1 : 1;

                    id = newrow.Id;

                    dc.tblGenres.Add(newrow);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }