public void SetNewParticipant(int companyId, int quoteId) { using (var context = new RFQEntities()) { IDbTransaction dbTrans = null; try { QuoteParticipant newQuoteParticipant = new QuoteParticipant() { CompanyID = companyId, QuoteID = quoteId }; context.Connection.Open(); dbTrans = context.Connection.BeginTransaction(); context.QuoteParticipants.AddObject(newQuoteParticipant); context.SaveChanges(); dbTrans.Commit(); } catch (Exception ex) { dbTrans.Rollback(); } finally { context.Connection.Close(); } } }
public bool setNewBid(QuoteBidDTO newBid, int companyId) { //bool result = false; QuoteParticipantService newParticipantSupplier = new QuoteParticipantService(); newParticipantSupplier.CompanyID = companyId; newParticipantSupplier.QuoteID = newBid.QuoteID; newParticipantSupplier.SetNewParticipant(companyId, newBid.QuoteID); using (TransactionScope transaction = new TransactionScope()) { try { QuoteParticipant newQuoteParticipant = new QuoteParticipant(); QuoteParticipantBase newParticipant; newParticipant = newParticipantSupplier.GetQuoteParticipant(companyId, newBid.QuoteID); newQuoteParticipant.QuoteParticipantID = newParticipant.QuoteParticipantID; QuoteBid newBidToCreate = new QuoteBid() { QuoteParticipantID = newQuoteParticipant.QuoteParticipantID, QuoteID = newBid.QuoteID, Amount = newBid.Amount, Notes = newBid.Notes }; using (var context = new RFQEntities()) { if (newBidToCreate.EntityState == EntityState.Detached) { context.QuoteBids.AddObject(newBidToCreate); } context.SaveChanges(); } } catch (Exception e) { transaction.Dispose(); return false; } transaction.Complete(); return true; } }
// This method returns the single Supplier Participant in the particular quote public QuoteParticipantBase GetQuoteParticipant(int companyId, int quoteId) { using (var context = new RFQEntities()) { QuoteParticipant quoteParticipant = new QuoteParticipant(); quoteParticipant = (from participant in context.QuoteParticipants where participant.QuoteID == quoteId && participant.CompanyID == companyId select participant).FirstOrDefault(); QuoteParticipantBase participantToReturn = new ParticipantDTO() { QuoteParticipantID = quoteParticipant.QuoteParticipantID, CompanyID = quoteParticipant.CompanyID, QuoteID = quoteParticipant.QuoteID }; return participantToReturn; } }
//Method that adds list of suppliers (Participants) to the quotaion Suppliers=Companies ****ADD PARTICIPANT**** // Method takes list of integers with companyIDs and the quotation ID public bool AddSuppliersToQuotation(List<ParticipantDTO> particpantsList) { bool check = false; using (TransactionScope transaction = new TransactionScope()) { try { using (var context = new RFQEntities()) { foreach (var item in particpantsList) { QuoteParticipant QuoteParticipantIn = new QuoteParticipant(); //Finding references for the Foreign Keys - QUOTE Quote existingQuote = context.Quotes.Single(q => q.QuoteID == item.QuoteID); //retriving references for the Foreign Key- Company Company existingCompany = context.Companies.Single(comp => comp.CompanyID == item.CompanyID); List<QuoteParticipant> existParticipant = (from p in context.QuoteParticipants where p.Quote.QuoteID == item.QuoteID && p.Company.CompanyID == item.CompanyID select p).ToList(); if (existParticipant.Count > 0) { } else { //Adding refernces QuoteParticipantIn.Company = existingCompany; QuoteParticipantIn.Quote = existingQuote; if (QuoteParticipantIn.EntityState == EntityState.Detached) { context.QuoteParticipants.AddObject(QuoteParticipantIn); } context.SaveChanges(); } }//end foreach }//end try } catch (DataExistis de) { } catch (Exception e) { transaction.Dispose(); check = false; return check; } transaction.Complete(); check = true; return check; } }
/// <summary> /// Deprecated Method for adding a new object to the QuoteParticipants EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToQuoteParticipants(QuoteParticipant quoteParticipant) { base.AddObject("QuoteParticipants", quoteParticipant); }
/// <summary> /// Create a new QuoteParticipant object. /// </summary> /// <param name="quoteParticipantID">Initial value of the QuoteParticipantID property.</param> /// <param name="companyID">Initial value of the CompanyID property.</param> /// <param name="quoteID">Initial value of the QuoteID property.</param> public static QuoteParticipant CreateQuoteParticipant(global::System.Int32 quoteParticipantID, global::System.Int32 companyID, global::System.Int32 quoteID) { QuoteParticipant quoteParticipant = new QuoteParticipant(); quoteParticipant.QuoteParticipantID = quoteParticipantID; quoteParticipant.CompanyID = companyID; quoteParticipant.QuoteID = quoteID; return quoteParticipant; }