Пример #1
0
        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;

            }
        }
Пример #2
0
        //Method that creates new Address for specific Company
        public bool CreateNewAddress(AddressDTO AddressNew)
        {
            bool check = false;
            using (TransactionScope transaction = new TransactionScope())
            {

                try
                {
                    Address AddressIn = new Address();
                    //Data transfer to the the AddressIn
                    AddressIn.Address1 = AddressNew.Address1;
                    AddressIn.Address2 = AddressNew.Address2;
                    AddressIn.City = AddressNew.City;
                    AddressIn.State = AddressNew.State;
                    AddressIn.PostalCode = AddressNew.PostalCode;
                    AddressIn.Country = AddressNew.Country;

                    using (var context = new RFQEntities())
                    {
                        //Finding references for the Foreign Keys
                        Company existingCompany = context.Companies.Single(p => p.CompanyID == AddressNew.CompanyID);

                        //Adding refernces
                        AddressIn.Company = existingCompany;

                        if (AddressIn.EntityState == EntityState.Detached)
                        {
                            context.Addresses.AddObject(AddressIn);
                        }

                        context.SaveChanges();

                    }

                }

                catch (Exception e)
                {
                    transaction.Dispose();
                    check = false;
                    return check;

                }
                transaction.Complete();
                check = true;
                return check;

            }
        }
Пример #3
0
        //Method that creates new Company
        public bool CreateNewCompany(CompanyDTO CompanyNew)
        {
            bool check = false;
            using (TransactionScope transaction = new TransactionScope())
            {

                try
                {
                    Company CompanyIn = new Company();
                    //Data transfer to the new company
                    CompanyIn.Name = CompanyNew.Name;

                    using (var context = new RFQEntities())
                    {
                        //Finding references for the Foreign Keys
                        Category existingCategory = context.Categories.Single(p => p.CategoryID == CompanyNew.CategoryID);
                        CompanyType existingCompanyType = context.CompanyTypes.Single(p => p.CompanyTypeID == CompanyNew.CompanyTypeID);
                        //Adding refernces
                        CompanyIn.Category = existingCategory;
                        CompanyIn.CompanyType = existingCompanyType;

                        if (CompanyIn.EntityState == EntityState.Detached)
                        {
                            context.Companies.AddObject(CompanyIn);
                        }

                        context.SaveChanges();

                    }

                }

                catch (Exception e)
                {
                    transaction.Dispose();
                    check = false;
                    return check;

                }
                transaction.Complete();
                check = true;
                return check;

            }
        }
Пример #4
0
        //Method that creates new Quotation ****CREATE RFQ BUTTON***
        public QuoteAdded CreateNewQuoation(QuoteDTO QuoteNew)
        {
            bool check = false;
            QuoteAdded QuoteValidation = new QuoteAdded();
            using (TransactionScope transaction = new TransactionScope())
            {

                try
                {
                    Quote QuoteIn = new Quote();
                    //Data transfer to the the AddressIn
                    QuoteIn.StartDate = QuoteNew.StartDate;
                    QuoteIn.EndDate = QuoteNew.EndDate;
                    QuoteIn.Status = 1;

                    using (var context = new RFQEntities())
                    {
                        //Finding references for the Foreign Keys
                        Company existingCompany = context.Companies.Single(q => q.CompanyID == QuoteNew.CompanyID);

                        //Adding refernces
                        QuoteIn.Company = existingCompany;

                        if (QuoteIn.EntityState == EntityState.Detached)
                        {
                            context.Quotes.AddObject(QuoteIn);
                        }

                        context.SaveChanges();

                        int id = QuoteIn.QuoteID;
                        QuoteValidation.LastId = id;

                    }

                }

                catch (Exception e)
                {
                    transaction.Dispose();
                    check = false;
                    QuoteValidation.Added = check;
                    return QuoteValidation;

                }
                transaction.Complete();
                check = true;
                QuoteValidation.Added = check;
                return QuoteValidation;

            }
        }
Пример #5
0
        //Method that terminate RFQ before the Due Date ****TERMINATE RFQ BUTTON****
        public bool TerminationRFQ(int quoteIDTerminate)
        {
            bool check = false;

            //using (TransactionScope transaction = new TransactionScope())
            //{

                try
                {
                    QuoteToTerminateDTO QuoteTerminate = new QuoteToTerminateDTO();

                    using (var context = new RFQEntities())
                    {

                        var quote = (from q in context.Quotes
                                     where q.QuoteID == quoteIDTerminate
                                     select q);

                        if (quote != null)
                        {
                            foreach (Quote q in quote)
                            {
                                q.Status = 0;

                            }

                        context.SaveChanges();

                        }
                     }

                 }

                catch (Exception e)
                {
                   // transaction.Dispose();
                    check = false;
                    return check;

                }
                //transaction.Complete();
                check = true;
                return check;
        }
Пример #6
0
        //Method that removes suppliers (Participants) from quotation ****REMOVE PARTICIPANT***
        //Method takes list of integers with ParticipantId
        public bool RemoveSuppliersFromQuotation(List<ParticipantDTO> participantIDList)
        {
            bool check = false;
            using (TransactionScope transaction = new TransactionScope())
            {

                try
                {

                    using (var context = new RFQEntities())
                    {

                        foreach (var item in participantIDList)
                        {

                            QuoteParticipant QuoteParticipantOut = (from part in context.QuoteParticipants
                                                                    where part.QuoteParticipantID == item.QuoteParticipantID
                                                                    select part).First();

                            if (QuoteParticipantOut != null)
                            {
                                context.DeleteObject(QuoteParticipantOut);
                                context.SaveChanges();

                            }

                        }//foreach

                    }//using

                }//try

                catch (Exception e)
                {
                    transaction.Dispose();
                    check = false;
                    return check;

                }
                transaction.Complete();
                check = true;
                return check;

            }//transaction
        }
Пример #7
0
        //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;

            }
        }
Пример #8
0
        //Method that adds new details row to the QuoteDetail ****ADD DETAILS BUTTON***
        public bool CreateNewQuoteDetail(QuoteDetailToCreateDTO QuoteDetailNew)
        {
            bool check = false;
            using (TransactionScope transaction = new TransactionScope())
            {

                try
                {
                    QuoteDetail QuoteDetailIn = new QuoteDetail();
                    //Data transfer to the object that will be added to the DB
                    QuoteDetailIn.Text = QuoteDetailNew.Text;
                    QuoteDetailIn.Value = QuoteDetailNew.Value;

                    using (var context = new RFQEntities())
                    {
                        //Finding references for the Foreign Keys
                        Quote existingQuote = context.Quotes.Single(qd => qd.QuoteID == QuoteDetailNew.QuoteID);

                        //Adding refernces
                        QuoteDetailIn.Quote = existingQuote;

                        if (QuoteDetailIn.EntityState == EntityState.Detached)
                        {
                            context.QuoteDetails.AddObject(QuoteDetailIn);
                        }

                        context.SaveChanges();

                    }

                }

                catch (Exception e)
                {
                    transaction.Dispose();
                    check = false;
                    return check;

                }
                transaction.Complete();
                check = true;
                return check;

            }
        }
        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();

                }
            }
        }