public ActionResult Create([Bind(Include = "ID,Username,Password,Fullname,Email,Active,CustomString1,CustomString2,CustomString3,CustomString4,CustomString5,CustomInt1,CustomInt2,CustomInt3,CustomInt4,CustomInt5,CustomBool1,CustomBool2,CustomBool3,CustomBool4,CustomBool5")] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Create([Bind(Include = "ID,Name,Detail,ImagePath,CustomString1,CustomString2,CustomString3,CustomString4,CustomString5,CustomInt1,CustomInt2,CustomInt3,CustomInt4,CustomInt5,CustomBool1,CustomBool2,CustomBool3,CustomBool4,CustomBool5")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "ID,Name,Birthday,Nationality,Detail,ImagePath,CustomString1,CustomString2,CustomString3,CustomString4,CustomString5,CustomInt1,CustomInt2,CustomInt3,CustomInt4,CustomInt5,CustomBool1,CustomBool2,CustomBool3,CustomBool4,CustomBool5")] Musician musician) { if (ModelState.IsValid) { db.Musicians.Add(musician); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(musician)); }
public ActionResult Create([Bind(Include = "ArtistID,ArtistName,ArtistPhoto")] Artist artist) { if (ModelState.IsValid) { db.Artists.Add(artist); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(artist)); }
public ActionResult Create([Bind(Include = "AlbumID,AlbumTitle,ReleaseDate,Genre,ArtWork,ArtistID")] Record record) { if (ModelState.IsValid) { db.Records.Add(record); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ArtistID = new SelectList(db.Artists, "ArtistID", "ArtistName", record.ArtistID); return(View(record)); }
public ActionResult Create([Bind(Include = "Song_ID,Category_ID,Detail")] Song_Category song_Category) { if (ModelState.IsValid) { db.Song_Category.Add(song_Category); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Category_ID = new SelectList(db.Categories, "ID", "Name", song_Category.Category_ID); ViewBag.Song_ID = new SelectList(db.Songs, "ID", "Name", song_Category.Song_ID); return(View(song_Category)); }
public ActionResult Create([Bind(Include = "ID,Name,Album_ID,Singer_ID,Musician_ID,ImagePath,SourcePath,Year,Format,BitRate,Tag,Size,Length,Rating,CustomString1,CustomString2,CustomString3,CustomString4,CustomString5,CustomInt1,CustomInt2,CustomInt3,CustomInt4,CustomInt5,CustomBool1,CustomBool2,CustomBool3,CustomBool4,CustomBool5")] Song song) { if (ModelState.IsValid) { db.Songs.Add(song); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Album_ID = new SelectList(db.Albums, "ID", "Name", song.Album_ID); ViewBag.Musician_ID = new SelectList(db.Musicians, "ID", "Name", song.Musician_ID); ViewBag.Singer_ID = new SelectList(db.Singers, "ID", "Name", song.Singer_ID); return(View(song)); }
//Insert the performer 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 tblPerformer performer = new tblPerformer { Id = this.Id, FirstName = this.FirstName, LastName = this.LastName, }; //Add it to the table and save changes dc.tblPerformers.Add(performer); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public int Update() { try { using (MusicEntities dc = new MusicEntities()) { //Retrieve the record from the DB tblComposer composer = dc.tblComposers.FirstOrDefault(c => c.Id == this.Id); //Update the properties composer.FirstName = this.FirstName; composer.LastName = this.LastName; composer.GenderId = this.GenderId; composer.LocationId = this.LocationId; composer.RaceId = this.RaceId; composer.Bio = this.Bio; //Save the changes return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
//Insert the composer 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 tblComposer composer = new tblComposer { Id = this.Id, FirstName = this.FirstName, LastName = this.LastName, GenderId = this.GenderId, LocationId = this.LocationId, RaceId = this.RaceId, Bio = this.Bio }; //Add it to the table and save changes dc.tblComposers.Add(composer); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
//Insert the pieceWriter 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 tblPieceWriter pieceWriter = new tblPieceWriter { Id = this.Id, ComposerTypeId = this.ComposerTypeId, ComposerId = this.ComposerId, PieceId = this.PieceId, }; //Add it to the table and save changes dc.tblPieceWriters.Add(pieceWriter); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public ActionResult PostComment(int musicId, int userId, string comment) { MusicEntities en = new MusicEntities(); var name = System.Web.HttpContext.Current.User.Identity.Name; var login = en.Logins.FirstOrDefault(a => a.Username.Equals(name)); User userLogin = null; if (login != null) { userLogin = login.User; } Comment com = new Comment { CommentDate = DateTime.Now, MusicId = musicId, UserId = userLogin.Id, Comment1 = comment, }; en.Comments.Add(com); en.SaveChanges(); return(Json(new { success = true })); }
public int Update() { try { using (MusicEntities dc = new MusicEntities()) { //Retrieve the record from the DB tblGroupMember groupmember = dc.tblGroupMembers.FirstOrDefault(c => c.Id == this.Id); //Update the properties groupmember.GroupId = this.GroupId; groupmember.PerformerId = this.PerformerId; groupmember.Instrument = this.Instrument; groupmember.StartDate = this.StartDate; groupmember.EndDate = this.EndDate; //Save the changes return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public int Update() { try { using (MusicEntities dc = new MusicEntities()) { //Retrieve the record from the DB tblPerformance performance = dc.tblPerformances.FirstOrDefault(c => c.Id == this.Id); //Update the properties performance.Name = this.Name; performance.Description = this.Description; performance.PerformanceDate = this.PerformanceDate; performance.pdfPath = this.PDFPath; performance.Location = this.Location; //Save the changes return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public ActionResult AddToFavorite(int userId, int musicId) { MusicEntities en = new MusicEntities(); var isExist = en.Favorites.Where(a => a.User.Id == userId && a.Music.Id == musicId).FirstOrDefault(); if (isExist != null) { return(Json(new { success = false, msg = "Music existed in your Favorites!" }, JsonRequestBehavior.AllowGet)); } else if (en.Favorites.Where(a => a.User.Id == userId).Count() > 100) { return(Json(new { success = false, msg = "Your favorites has reached limit (100 songs)" }, JsonRequestBehavior.AllowGet)); } else { var fav = new Favorite { MusicId = musicId, UserId = userId, }; en.Favorites.Add(fav); en.SaveChanges(); return(Json(new { success = true, msg = "Music has been added to your Favorites!" }, JsonRequestBehavior.AllowGet)); } }
//Insert the composerType 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 tblComposerType composerType = new tblComposerType { Id = this.Id, Description = this.Description }; //Add it to the table and save changes dc.tblComposerTypes.Add(composerType); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
//Insert the director 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 tblDirector director = new tblDirector { Id = this.Id, FirstName = this.FirstName, LastName = this.LastName, Bio = this.Bio, BirthDate = this.BirthDate }; //Add it to the table and save changes dc.tblDirectors.Add(director); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
//Insert the groupmember 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 tblGroupMember groupmember = new tblGroupMember { Id = this.Id, GroupId = this.GroupId, PerformerId = this.PerformerId, Instrument = this.Instrument, StartDate = this.StartDate, EndDate = this.EndDate, }; //Add it to the table and save changes dc.tblGroupMembers.Add(groupmember); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
//Insert the group 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 tblGroup group = new tblGroup { Id = this.Id, Name = this.Name, Description = this.Description, FoundedDate = this.FoundedDate, }; //Add it to the table and save changes dc.tblGroups.Add(group); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public int Delete() { try { using (MusicEntities dc = new MusicEntities()) { //Retrieve it from the DB tblPiece piece = dc.tblPieces.FirstOrDefault(p => p.Id == this.Id); //Remove the piece dc.tblPieces.Remove(piece); foreach (Genre genre in Genres) { genre.Delete(); } foreach (PieceWriter pieceWriter in PieceWriters) { pieceWriter.Delete(); } //Save the changes return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public int Update() { try { using (MusicEntities dc = new MusicEntities()) { //Retrieve the record from the DB tblPiece piece = dc.tblPieces.FirstOrDefault(p => p.Id == this.Id); //Update the properties piece.Id = this.Id; piece.Name = this.Name; piece.GradeLevel = this.GradeLevel; piece.PefromanceNotes = this.PerformanceNotes; //Set the year written if (this.YearWritten >= 0) { piece.YearWritten = this.YearWritten; } else { piece.YearWritten = null; } //Save the changes return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
//Insert the performance 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 tblPerformancePiece performancePiece = new tblPerformancePiece { Id = this.Id, Notes = this.Notes, MP3Path = this.MP3Path, GroupId = this.GroupId, PerformanceId = this.PerformanceId, DirectorId = this.DirectorId, PieceId = this.PieceId }; //Add it to the table and save changes dc.tblPerformancePieces.Add(performancePiece); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public int Update() { try { using (MusicEntities dc = new MusicEntities()) { //Retrieve the record from the DB tblPerformancePiece performancePiece = dc.tblPerformancePieces.FirstOrDefault(c => c.Id == this.Id); //Update the properties performancePiece.Notes = this.Notes; performancePiece.MP3Path = this.MP3Path; performancePiece.GroupId = this.GroupId; performancePiece.DirectorId = this.DirectorId; performancePiece.PieceId = this.PieceId; performancePiece.PerformanceId = this.PerformanceId; //Save the changes return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public void Delete() { using (MusicEntities dc = new MusicEntities()) { tblPieceGenre pieceGenre = dc.tblPieceGenres.FirstOrDefault(pg => pg.PieceId == PieceId && pg.GenreId == GenreId); dc.tblPieceGenres.Remove(pieceGenre); dc.SaveChanges(); } }
public static async Task ResetViewEachWeek() { MusicEntities en = new MusicEntities(); string sql1 = "UPDATE Music SET _View = 0"; string sql2 = "UPDATE Album SET _View = 0"; string sql3 = "UPDATE Singer SET _View = 0"; await en.Database.ExecuteSqlCommandAsync(sql1); await en.Database.ExecuteSqlCommandAsync(sql2); await en.Database.ExecuteSqlCommandAsync(sql3); en.SaveChanges(); }
public ActionResult Create_Post() { var musicmodel = new Music_Instrument(); TryUpdateModel(musicmodel); using (var r = new MusicEntities()) { r.Music_Instruments.Add(musicmodel); r.SaveChanges(); } return(RedirectToAction("Index")); }
public async Task <ActionResult> Signup(RegisterUserViewModel model) { MusicEntities en = new MusicEntities(); var login = en.Logins.FirstOrDefault(a => a.Username.Equals(model.Username)); if (login != null) { return(Json(new { success = false, message = "Username exist, Please choose another username!" })); } else { try { string storageUrl = "musicproject-9f3c5.appspot.com"; string date = DateTime.Now.ToString("yyyyMMddHHmmssffff"); var stream2 = model.ImageBase.InputStream; var task2 = new FirebaseStorage(storageUrl) .Child("MusicProject") .Child("Images") .Child(date + "-" + model.ImageBase.FileName) .PutAsync(stream2); task2.Progress.ProgressChanged += (s, e) => ProgressHub.SendMessage("Uploading User Avatar ... (" + Math.Round((e.Position * 1.0 / e.Length * 100), 0) + "%)"); string imageUrl = await task2; Login newUser = new Login { Username = model.Username, Password = model.Password, User = new User { Avatar = imageUrl, FirstName = model.Firstname, LastName = model.Lastname, Phone = model.Phone, Gender = model.Gender, Email = model.Email, } }; en.Logins.Add(newUser); en.SaveChanges(); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message })); } } return(Json(new { success = true })); }
public void UpdateTest() { using (MusicEntities dc = new MusicEntities()) { tblPerformer performer = dc.tblPerformers.FirstOrDefault(a => a.FirstName == "PL First Name Test"); performer.LastName = "PL Last Name Updated"; dc.SaveChanges(); tblPerformer retrievedPerformer = dc.tblPerformers.FirstOrDefault(a => a.LastName == "PL Last Name Updated"); Assert.IsNotNull(retrievedPerformer); } }
public ActionResult Edit_Post(string code) { var musicmodel = new Music_Instrument(); TryUpdateModel(musicmodel); using (var r = new MusicEntities()) { var m = r.Music_Instruments.Where(x => x.InstrumentCode == code).FirstOrDefault(); TryUpdateModel(m); r.SaveChanges(); } return(RedirectToAction("Index")); }
public void DeleteTest() { using (MusicEntities dc = new MusicEntities()) { tblPerformer performer = dc.tblPerformers.FirstOrDefault(a => a.FirstName == "PL First Name Test"); dc.tblPerformers.Remove(performer); dc.SaveChanges(); tblPerformer retrievedPerformer = dc.tblPerformers.FirstOrDefault(a => a.FirstName == "PL First Name Test"); Assert.IsNull(retrievedPerformer); } }