public void DeleteOpportunity(Opportunity opportunity)
        {
            try
            {
                context.Opportunities.Attach(opportunity);
                context.Entry(opportunity).State = EntityState.Deleted;
                SaveChanges();
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
Ejemplo n.º 2
0
 public bool CheckOppportintyName(Opportunity opportunity)
 {
     bool msg = false;
     int companyid = Convert.ToInt32(HttpContext.Current.Session["CompanyID"]);
     var duplicateOpportunity =
         opportunitiesRepository.GetOpportunityByName(opportunity.Name, companyid).FirstOrDefault();
     if (duplicateOpportunity != null )
     {
         if (duplicateOpportunity.Name == opportunity.Name)
         {
             msg = true;
         }
     }
     return msg;
 }
        public long UpdateOpportunity(Opportunity opportunity)
        {
            try
            {
                var currentOpportunity = context.Opportunities.Find(opportunity.OpportunityID);
                context.Entry(currentOpportunity).CurrentValues.SetValues(opportunity);
                SaveChanges();
                return opportunity.OpportunityID;

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public long leadToOpportunityInsert(Opportunity opportunity)
        {
            try
            {
                context.Entry(opportunity).State = EntityState.Added;
                context.SaveChanges();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return opportunity.OpportunityID;
        }
        public long InsertOpportunity(Opportunity opportunity)
        {
            try
            {
                opportunity.CreatedTime = DateTime.Now;
                opportunity.ModifiedTime = DateTime.Now;
                context.Entry(opportunity).State = EntityState.Added;
                context.SaveChanges();
                return opportunity.OpportunityID;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
Ejemplo n.º 6
0
 public void DeleteOpportunity(Opportunity opportunity)
 {
     opportunitiesRepository.DeleteOpportunity(opportunity);
 }
Ejemplo n.º 7
0
        private void ValidateOpportunity(Opportunity opportunity)
        {
            if (opportunity.Name != null)
            {
                int companyid = Convert.ToInt32(HttpContext.Current.Session["CompanyID"]);
                var duplicateOpportunity =
                    opportunitiesRepository.GetOpportunityByName(opportunity.Name, companyid).FirstOrDefault();
                if (duplicateOpportunity != null && duplicateOpportunity.OpportunityID != opportunity.OpportunityID)
                {
                    if (duplicateOpportunity.Name == opportunity.Name)
                    {
                        throw new DuplicateLeadException(String.Format(
                            "Opportunity Name {0} is already exist",
                            duplicateOpportunity.Name
                                                             ));

                    }
                }
            }
        }
Ejemplo n.º 8
0
        public long UpdateOpportunity(Opportunity opportunity)
        {
            ValidateOpportunity(opportunity);
            try
            {
                return opportunitiesRepository.UpdateOpportunity(opportunity);

            }
            catch (Exception ce)
            {

                throw ce;
            }
        }
Ejemplo n.º 9
0
 public long leadToOpportunityInsert(Opportunity opportunity)
 {
     ValidateOpportunity(opportunity);
     return opportunitiesRepository.leadToOpportunityInsert(opportunity);
 }
Ejemplo n.º 10
0
        //public IEnumerable<Opportunity> GetOpportunitiessByCompanyID()
        //{
        //    return opportunitiesRepository.GetOpportunitiessByCompanyID();
        //}
        public long InsertOpportunity(Opportunity opportunity)
        {
            ValidateOpportunity(opportunity);
            try
            {
                return opportunitiesRepository.InsertOpportunity(opportunity);

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
Ejemplo n.º 11
0
        protected void ConvertButton_Click(object sender, EventArgs e)
        {
            long opportunityID;
            int companyid = Convert.ToInt32(HttpContext.Current.Session["CompanyID"]);
            long userid = Convert.ToInt32(HttpContext.Current.Session["UserID"]);
            long leadID = Convert.ToInt32(Session["EditLeadID"]);
            var leads = leadBL.CheckConvertedLeadById(leadID);

            if (leads.Count() > 0)
            {
                var lead = leads.FirstOrDefault();
                string firstName = lead.FirstName;
                string lastName = lead.LastName;
                string accountName = lead.AccountName;
                Session["ContactfirstName"] = firstName;
                Session["ContactLastName"] = lastName;
                Opportunity opportunity = new Opportunity();
                opportunity.Name = accountName;
                opportunity.AccountID = Convert.ToInt64(lead.AccountID);
                opportunity.TeamID = lead.TeamID;
                opportunity.AssignedUserID = lead.AssignedUserID;
                opportunity.LeadSourceID = lead.LeadSourceID;
                opportunity.CurrencyID = 1;
                opportunity.CreatedTime = DateTime.Now;
                opportunity.ModifiedTime = DateTime.Now;
                opportunity.CompanyID = companyid;
                opportunity.CreatedBy = userid;

                bool exists = opportunityBL.CheckOppportintyName(opportunity);
                if (exists == true)
                {
                    Label1.Text = (String.Format(
                        "Opportunity Name {0} is already exist",
                        opportunity.Name
                        ));
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "ShowAlertModal();", true);

                }
                else
                {

                    opportunityID = opportunityBL.leadToOpportunityInsert(opportunity);
                    Session["OpportunityID"] = opportunityID;

                    opportunityID = Convert.ToInt64(Session["OpportunityID"]);
                    string firstname = Session["ContactfirstName"].ToString();
                    string lastname = Session["ContactLastName"].ToString();
                    string name = firstname + " " + lastname;
                    //update lead of newly converted opportunity
                    //Lead lead1=new Lead();
                    //lead1.LeadID = leadID;
                    //lead1.OpportunityID = Convert.ToInt64(opportunityID);
                    //lead1.OpportunityName = firstname + " " + lastname;
                    //leadBL.UpdateLeads(lead1);
                    leadBL.UpdateConvertedLead(leadID, opportunityID, name);
                    Literal1.Text = "Convert Successfully";
                    Label1.Text = "This Lead is Convert to Opportunity Successfully";
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "ShowAlertModal();",
                                                            true);
                }

            }
            else
                {

                    Literal1.Text = "!!!Not converted";
                    Label1.Text = "This Lead is already converted to Opportunity";
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "ShowAlertModal();", true);
                }

                //Session.Remove("FirstName");
                //Session.Remove("LastName");
        }