public void Save(Model.EDEntities db) { var result = (from p in db.Certificates where p.SerialNumber == this.SerialNumber select p).Count(); if (result > 0) { throw new ApplicationException("Person with this certificate has already been registered"); } var certificate = this.Map(); db.Certificates.Add(certificate); db.SaveChanges(); this.ID = certificate.ID; }
public void Save(Model.EDEntities db) { var result = (from p in db.People where p.Login.ToUpper() == this.Login.ToUpper() select p).Count(); if (result > 0) { throw new ApplicationException("Person with this login has already been registered"); } var person = this.Map(); db.People.Add(person); db.SaveChanges(); this.ID = person.ID; }
public void Vote() { using (var db = new Model.EDEntities()) { var result = (from p in db.PetitionVotes where p.PetitionID == this.Petition.ID && (p.PersonID == this.Person.ID || p.CertificateID == this.Certificate.ID) select p).Count(); if (result > 0) throw new ApplicationException("This vote was already counted"); var vote = this.Map(); db.PetitionVotes.Add(vote); db.SaveChanges(); this.ID = vote.ID; } }
public void Vote() { using (var db = new Model.EDEntities()) { var result = (from p in db.AgreementVotes where p.AgreementID == this.Agreement.ID && (p.PersonID == this.Person.ID || p.CertificateID == this.Certificate.ID) select p).Count(); if (result > 0) { throw new ApplicationException("This vote was already counted"); } var vote = this.Map(); db.AgreementVotes.Add(vote); db.SaveChanges(); this.ID = vote.ID; } }
public OperationResult Register(People person, Model.BusinessEntities.Certificate cert) { try { using (Model.EDEntities db = new Model.EDEntities()) { using (TransactionScope scope = new TransactionScope()) { person.Save(db); cert.Save(db); scope.Complete(); } } } catch (Exception ex) { return OperationResult.Fail(-1, ex.Message); } return OperationResult.Success(1, "Person has successfully been registered"); }
public OperationResult Register(People person, Model.BusinessEntities.Certificate cert) { try { using (Model.EDEntities db = new Model.EDEntities()) { using (TransactionScope scope = new TransactionScope()) { person.Save(db); cert.Save(db); scope.Complete(); } } } catch (Exception ex) { return(OperationResult.Fail(-1, ex.Message)); } return(OperationResult.Success(1, "Person has successfully been registered")); }
public static Agreement GetAgreement(long ID) { using (var db = new Model.EDEntities()) { var result = from p in db.Agreements where p.ID == ID select p; var first = result.FirstOrDefault(); if (first == default(Model.Agreement)) { throw new ApplicationException("Agreement not found {ID = " + ID.ToString() + "}"); } var amount = (from p in db.AgreementVotes where p.AgreementID == first.ID select p).Count(); Agreement agreement = new Agreement(first); return(agreement); } }
public static Agreement GetAgreement(long ID) { using (var db = new Model.EDEntities()) { var result = from p in db.Agreements where p.ID == ID select p; var first = result.FirstOrDefault(); if (first == default(Model.Agreement)) throw new ApplicationException("Agreement not found {ID = " + ID.ToString() + "}"); var amount = (from p in db.AgreementVotes where p.AgreementID == first.ID select p).Count(); Agreement agreement = new Agreement(first); return agreement; } }