public static Data.Rating SaveRating(IDBSession dbs, Data.Rating rating) { using (NHibernate.ITransaction transaction = dbs.Session.BeginTransaction()) { DB.Rating dbRating = null; if (rating.MessageID != Guid.Empty) { dbRating = dbs.Session.Get <DB.Rating>(rating.MessageID); } if (dbRating == null) { dbRating = new DB.Rating(rating); } else { dbRating.Value = rating.Value; } DB.Message dbMessage = dbs.Session.QueryOver <DB.Message>().Fetch(x => x.Comments).Eager.Where(x => x.ID == rating.MessageID).SingleOrDefault <DB.Message>(); if (dbMessage != null) { //if (dbMessage.Ratings == null) dbMessage.Ratings = new List<Rating>(); dbMessage.Ratings.Add(dbRating); dbs.Session.SaveOrUpdate(dbMessage); transaction.Commit(); rating = dbRating.ToData(); } } return(rating); }
public Models.Movie Update(Models.Movie movieModel) { if (movieModel.Format == null) { throw new ArgumentNullException("Format", "The Format property must not be null."); } if (movieModel.Director == null) { throw new ArgumentNullException("Director", "The Director property must not be null."); } var existing = db.Movies.SingleOrDefault(x => x.Id == movieModel.Id); if (existing == null) { return(null); } existing.Cost = movieModel.Cost; existing.Description = movieModel.Description; existing.Title = movieModel.Title; existing.ImagePath = movieModel.ImagePath; Data.Director existingDirectors = db.Directors.SingleOrDefault(x => x.Id == movieModel.Director.Id); existing.Director = existingDirectors ?? throw new ArgumentException("The associated Director cannot be found."); Data.Format existingFormats = db.Formats.SingleOrDefault(x => x.Id == movieModel.Format.Id); existing.Format = existingFormats ?? throw new ArgumentException("The associated format cannot be found."); Data.Rating existingRatings = db.Ratings.SingleOrDefault(x => x.Id == movieModel.Rating.Id); existing.Rating = existingRatings ?? throw new ArgumentException("The associated Rating cannot be found."); db.SaveChanges(); return(movieModel); }
public int Add(Models.Movie movieModel) { if (movieModel.Format == null) { throw new ArgumentNullException("Format", "The Format property must not be null."); } if (movieModel.Director == null) { throw new ArgumentNullException("Director", "The Director property must not be null."); } Data.Movie newRow = new Data.Movie(); newRow.Cost = movieModel.Cost; newRow.Description = movieModel.Description; newRow.Title = movieModel.Title; newRow.ImagePath = movieModel.ImagePath; Data.Rating existingRatings = db.Ratings.SingleOrDefault(x => x.Id == movieModel.Rating.Id); newRow.Rating = existingRatings ?? throw new ArgumentException("The associated rating cannot be found."); Data.Director existingDirectors = db.Directors.SingleOrDefault(x => x.Id == movieModel.Director.Id); newRow.Director = existingDirectors ?? throw new ArgumentException("The associated Director cannot be found."); Data.Format existingFormats = db.Formats.SingleOrDefault(x => x.Id == movieModel.Format.Id); newRow.Format = existingFormats ?? throw new ArgumentException("The associated format cannot be found."); db.Movies.Add(newRow); db.SaveChanges(); return(newRow.Id); }
public override IAnswer HandlePOST() { Form.Rating inputData = new Form.Rating(Data.Post.Input); Data.Rating inputRating = inputData.ToData(); Data.Rating rating = DB.Controller.SaveRating(Server.DBSession, inputRating); return(new CJE.Http.RequestAnswer.Json(rating)); }
public int Create(Models.Rating rating) { Data.Rating newRating = new Data.Rating { Description = rating.Description }; db.Ratings.Add(newRating); db.SaveChanges(); return(newRating.Id); }
public Rating(Data.Rating source) { this.MessageID = source.MessageID; this.Value = source.Value; }