public void DeletePost(int id ) { try { SessionInitializeTransaction(); PostEN postEN = (PostEN)session.Load(typeof(PostEN), id); session.Delete(postEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is PickadosGenNHibernate.Exceptions.ModelException) { throw ex; } throw new PickadosGenNHibernate.Exceptions.DataLayerException("Error in PostCAD.", ex); } finally { SessionClose(); } }
public PostEN ReadOIDDefault(int id ) { PostEN postEN = null; try { SessionInitializeTransaction(); postEN = (PostEN)session.Get(typeof(PostEN), id); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is PickadosGenNHibernate.Exceptions.ModelException) { throw ex; } throw new PickadosGenNHibernate.Exceptions.DataLayerException("Error in PostCAD.", ex); } finally { SessionClose(); } return(postEN); }
public PickadosGenNHibernate.EN.Pickados.PostEN PublishPost(TimeSpan p_created_at, TimeSpan p_modified_at, double p_stake, string p_description, bool p_private, System.Collections.Generic.IList <int> p_pick, int p_tipster, double p_totalOdd, PickadosGenNHibernate.Enumerated.Pickados.PickResultEnum p_postResult, PickCEN pickCEN) { /*PROTECTED REGION ID(PickadosGenNHibernate.CEN.Pickados_Post_publishPost) ENABLED START*/ // Write here your custom code... PostEN post = null; List <int> picks_id = new List <int>(); foreach (int id_pick in p_pick) { PickEN pick = pickCEN.GetByID(id_pick); if (DateTime.Now <= pick.Event_rel.Date) { picks_id.Add(id_pick); } } if (picks_id.Count > 0) { int post_id = NewPost(p_created_at, p_modified_at, p_stake, p_description, p_private, picks_id, p_tipster, p_totalOdd, p_postResult); post = GetByID(post_id); } return(post); /*PROTECTED REGION END*/ }
public PostEN GetByID(int id ) { PostEN postEN = null; postEN = _IPostCAD.GetByID(id); return(postEN); }
public int NewPost(TimeSpan p_created_at, TimeSpan p_modified_at, double p_stake, string p_description, bool p_private, System.Collections.Generic.IList <int> p_pick, int p_tipster, double p_totalOdd, PickadosGenNHibernate.Enumerated.Pickados.PickResultEnum p_postResult) { PostEN postEN = null; int oid; //Initialized PostEN postEN = new PostEN(); postEN.Created_at = p_created_at; postEN.Modified_at = p_modified_at; postEN.Stake = p_stake; postEN.Description = p_description; postEN.Private_ = p_private; postEN.Pick = new System.Collections.Generic.List <PickadosGenNHibernate.EN.Pickados.PickEN>(); if (p_pick != null) { foreach (int item in p_pick) { PickadosGenNHibernate.EN.Pickados.PickEN en = new PickadosGenNHibernate.EN.Pickados.PickEN(); en.Id = item; postEN.Pick.Add(en); } } else { postEN.Pick = new System.Collections.Generic.List <PickadosGenNHibernate.EN.Pickados.PickEN>(); } if (p_tipster != -1) { // El argumento p_tipster -> Property tipster es oid = false // Lista de oids id postEN.Tipster = new PickadosGenNHibernate.EN.Pickados.TipsterEN(); postEN.Tipster.Id = p_tipster; } postEN.TotalOdd = p_totalOdd; postEN.PostResult = p_postResult; //Call to PostCAD oid = _IPostCAD.NewPost(postEN); return(oid); }
// Modify default (Update all attributes of the class) public void ModifyDefault(PostEN post) { try { SessionInitializeTransaction(); PostEN postEN = (PostEN)session.Load(typeof(PostEN), post.Id); postEN.Created_at = post.Created_at; postEN.Modified_at = post.Modified_at; postEN.Stake = post.Stake; postEN.Description = post.Description; postEN.Private_ = post.Private_; postEN.TotalOdd = post.TotalOdd; postEN.PostResult = post.PostResult; session.Update(postEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is PickadosGenNHibernate.Exceptions.ModelException) { throw ex; } throw new PickadosGenNHibernate.Exceptions.DataLayerException("Error in PostCAD.", ex); } finally { SessionClose(); } }
public void ModifyPost(int p_Post_OID, TimeSpan p_created_at, TimeSpan p_modified_at, double p_stake, string p_description, bool p_private, double p_totalOdd, PickadosGenNHibernate.Enumerated.Pickados.PickResultEnum p_postResult) { PostEN postEN = null; //Initialized PostEN postEN = new PostEN(); postEN.Id = p_Post_OID; postEN.Created_at = p_created_at; postEN.Modified_at = p_modified_at; postEN.Stake = p_stake; postEN.Description = p_description; postEN.Private_ = p_private; postEN.TotalOdd = p_totalOdd; postEN.PostResult = p_postResult; //Call to PostCAD _IPostCAD.ModifyPost(postEN); }
public int NewPost(PostEN post) { try { SessionInitializeTransaction(); if (post.Pick != null) { for (int i = 0; i < post.Pick.Count; i++) { post.Pick [i] = (PickadosGenNHibernate.EN.Pickados.PickEN)session.Load(typeof(PickadosGenNHibernate.EN.Pickados.PickEN), post.Pick [i].Id); post.Pick [i].Post.Add(post); } } if (post.Tipster != null) { // Argumento OID y no colección. post.Tipster = (PickadosGenNHibernate.EN.Pickados.TipsterEN)session.Load(typeof(PickadosGenNHibernate.EN.Pickados.TipsterEN), post.Tipster.Id); post.Tipster.Post .Add(post); } session.Save(post); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is PickadosGenNHibernate.Exceptions.ModelException) { throw ex; } throw new PickadosGenNHibernate.Exceptions.DataLayerException("Error in PostCAD.", ex); } finally { SessionClose(); } return(post.Id); }
public void PublishPostOkTest() { //Create mocks var postCADMock = new Mock<IPostCAD>(); var pickCADMock = new Mock<IPickCAD>(); //Prepare data to be returned by mocks List<int> pick_ids = new List<int>(); pick_ids.Add(1); PickEN pick = new PickEN(); Event_EN eventPick = new Event_EN(); eventPick.Date = new DateTime(2018, 1, 16, 15, 0, 0); pick.Event_rel = eventPick; List<PickEN> picks = new List<PickEN>(); picks.Add(pick); PostEN expectedPost = new PostEN(); expectedPost.Pick = picks; //Setup mock methods postCADMock.Setup(mock => mock.NewPost(It.IsAny<PostEN>())).Returns(1); postCADMock.Setup(mock => mock.GetByID(It.IsAny<int>())).Returns(expectedPost); pickCADMock.Setup(mock => mock.GetByID(It.IsAny<int>())).Returns(pick); PostCEN postCEN = new PostCEN(postCADMock.Object); PickCEN pickCEN = new PickCEN(pickCADMock.Object); PostEN actualPost = postCEN.PublishPost(It.IsAny<TimeSpan>(), It.IsAny<TimeSpan>(), It.IsAny<Double>(), It.IsAny<string>(), It.IsAny<bool>(), pick_ids, It.IsAny<int>(), It.IsAny<double>(), It.IsAny<PickResultEnum>(), pickCEN); //Test method (check if picks are equal) Assert.AreEqual(expectedPost.Pick, actualPost.Pick); Assert.IsNotNull(expectedPost); //Verify mocks postCADMock.Verify(mock => mock.NewPost(It.IsAny<PostEN>()), Times.Once); postCADMock.Verify(mock => mock.GetByID(It.IsAny<int>()), Times.Once); pickCADMock.Verify(mock => mock.GetByID(It.IsAny<int>()), Times.AtLeastOnce); }