public bool AddView(int ProductId, int UserId) { var product = Db.Products.Find(ProductId); if (product == null) { return(false); } var user = Db.Users.Find(UserId); if (user == null) { return(false); } var query1 = from m in Db.ProductVieweds where m.Product.Id == product.Id select m; var query2 = from m in query1 where m.User.Id == user.Id select m; foreach (var it in query2) { return(false); } ViewedProduct vp = new ViewedProduct { Product = product, User = user, Current = 0, End = false, Reminder = "", Condition = "", Star = false }; Db.ProductVieweds.Add(vp); Db.SaveChanges(); return(true); }
private void _wsus_UpdateApprovalChange(IUpdate approvedUpdate) { Logger.EnteringMethod(approvedUpdate.Title); ViewedProduct.RefreshUpdate(approvedUpdate); foreach (DataGridViewRow row in dgvUpdateList.SelectedRows) { if (((IUpdate)row.Cells["UpdateId"].Value).Id.UpdateId == approvedUpdate.Id.UpdateId) { row.Cells["UpdateId"].Value = approvedUpdate; dgvUpdateList_SelectionChanged(null, null); break; } } }
internal void UpdateDeleted(IUpdate deletedUpdate) { Logger.EnteringMethod(deletedUpdate.Title); ViewedProduct.RemoveUpdate(deletedUpdate); foreach (DataGridViewRow row in dgvUpdateList.SelectedRows) { if (((IUpdate)row.Cells["UpdateId"].Value) == deletedUpdate) { dgvUpdateList.Rows.Remove(row); if (ContentChanged != null) { ContentChanged(); } break; } } }
public ViewDetails GetViewDetails(int ProductId, int UserId) { ViewDetails vd = new ViewDetails(); vd.ProductId = ProductId; vd.UserId = UserId; var query1 = from m in Db.ProductVieweds where m.Product.Id == ProductId select m; var query2 = from m in query1 where m.User.Id == UserId select m; ViewedProduct view = null; foreach (var it in query2) { view = it; } if (view != null) { vd.ViewId = view.Id; vd.CurrentEpisode = view.Current; } vd.MaxEpisode = 0; vd.AvatarURI = view.Product.AvatarURI; vd.Year = 0; vd.Names = new List <string>(); vd.Names.Add(view.Product.Name); vd.FromURI = null; vd.PosterFromURI = null; if (view != null) { vd.Reminder = view.Reminder; vd.Condition = view.Condition; vd.Star = view.Star; } foreach (var it in view.Product.MetaData) { switch (it.Type) { case TypeOfMetaProduct.NumberOfEpisode: vd.MaxEpisode = it.Int; break; case TypeOfMetaProduct.Begin: vd.Year = it.Date.Year; break; case TypeOfMetaProduct.Name: vd.Names.Add(it.String); break; case TypeOfMetaProduct.FromURI: vd.FromURI = it.String; break; case TypeOfMetaProduct.PosterFromURI: vd.PosterFromURI = it.String; break; } } return(vd); }