public QuickStartController(IUnitOfWork uow)
     : base(uow)
 {
     QuickStartViewModel = new EntityViewModel<TBL_OPPORTUNITIES>();
     QuickStartViewModel.BaseModel = this.BaseVM;
     TBL_OPPORTUNITIES opportunity = new TBL_OPPORTUNITIES();
     opportunity.NAME = "test opp";
     QuickStartViewModel.EntityModel = new TBL_OPPORTUNITIES();
 }
 private bool VerifyPipelineRequiredFields(TBL_OPPORTUNITIES opportunity)
 {
     return (opportunity.COMPANYID > 0 &&
         opportunity.CONTACTID > 0 &&
         !string.IsNullOrEmpty(opportunity.NAME) &&
         opportunity.ProductID > 0 &&
         !string.IsNullOrEmpty(opportunity.VALUE.Value.ToString()) &&
         opportunity.CLOSEDATE.HasValue &&
         !string.IsNullOrEmpty(opportunity.Pain) &&
         opportunity.STATUSID > 0 &&
         opportunity.SourceID > 0 &&
         opportunity.TypeID > 0);
 }
        public HttpResponseMessage SavePipeline(TBL_OPPORTUNITIES opportunity)
        {
            try
            {
                if (!VerifyPipelineRequiredFields(opportunity))
                    throw new Exception("Pipeline required fields are not submiited");
                if (opportunity.ID > 0)
                {
                    opportunity.UpdatedBy = CurrentUser.UserId.ToString();
                    opportunity.UpdatedDate = DateTime.Now;
                    uow.Repository<TBL_OPPORTUNITIES>().Update(opportunity);
                }
                else
                {
                    opportunity.CreatedBy = CurrentUser.UserId.ToString();
                    opportunity.CreatedDate = DateTime.Now;
                    opportunity.IsActive = true;
                    uow.Repository<TBL_OPPORTUNITIES>().Add(opportunity);
                }

                uow.Save();
                return Request.CreateResponse(opportunity);
            }
            catch (Exception ex)
            {
                throw new Exception("There is a problem in Saving Pipeline Information. Please try again later.", ex);
            }
        }
 protected virtual TBL_OPPORTUNITIES Update(TBL_OPPORTUNITIES opportunity)
 {
     OpportunitiesRepository opportunitySource = new OpportunitiesRepository();
     opportunitySource.Update(opportunity);
     RefreshEntities();
     return opportunity;
 }
 protected virtual TBL_OPPORTUNITIES Save(TBL_OPPORTUNITIES opportunity)
 {
     OpportunitiesRepository opportunitySource = new OpportunitiesRepository(); ;
     opportunitySource.Add(opportunity);
     UserEntitiesFactory.ReLoad();
     return opportunity;
 }
 private bool VerifyRequiredFields(TBL_OPPORTUNITIES opportunity)
 {
     return (opportunity.COMPANYID > 0 &&
         opportunity.CONTACTID > 0 &&
         !string.IsNullOrEmpty(opportunity.NAME) &&
         !string.IsNullOrEmpty(opportunity.SALESREPFIRSTNAME) &&
         !string.IsNullOrEmpty(opportunity.SALESREPLASTNAME) &&
         opportunity.ProductID > 0 &&
         !string.IsNullOrEmpty(opportunity.VALUE.Value.ToString()) &&
         opportunity.CLOSEDATE.HasValue &&
         !string.IsNullOrEmpty(opportunity.Pain));
 }
        public HttpResponseMessage Save(TBL_OPPORTUNITIES opportunity)
        {
            if(!VerifyRequiredFields(opportunity))
                return new HttpResponseMessage(HttpStatusCode.InternalServerError);
            if (opportunity.ID > 0)
            {
                opportunity.UpdatedBy = CurrentUser.UserId.ToString();
                opportunity.UpdatedDate = DateTime.Now;
                uow.Repository<TBL_OPPORTUNITIES>().Update(opportunity);
            }
            else
            {
                opportunity.CreatedBy = CurrentUser.UserId.ToString();
                opportunity.CreatedDate = DateTime.Now;
                opportunity.IsActive = true;
                uow.Repository<TBL_OPPORTUNITIES>().Add(opportunity);
            }

            uow.Save();
            return Request.CreateResponse(opportunity);
        }
    protected void lbtnAdd_Click(object sender, EventArgs e)
    {
        UserOpportunities = null;
        TBL_OPPORTUNITIES opportunity = null;
        if (lbtnAdd.Text == "Add")
        {
            opportunity = new TBL_OPPORTUNITIES();

            BindFieldsToOpportunity(opportunity);

            opportunity.UpdatedBy = CurrentUser.UserId.ToString();
            opportunity.CreatedBy = CurrentUser.UserId.ToString();
            opportunity.IsActive = true;
            //Default setup in DB is not working to do check
            opportunity.CreatedDate = DateTime.Now;
            opportunity.UpdatedDate = DateTime.Now;

            Save(opportunity);
            lblResult.Text = "Opportunity with Opportunity ID = " + opportunity.OpportunityID.Value.ToString() + " created Successfully!";
        }
        else
        {
            OpportunityID = int.Parse(Request.QueryString["id"]);
            opportunity = GetOpportunity(OpportunityID);

            BindFieldsToOpportunity(opportunity);

            opportunity.UpdatedBy = CurrentUser.UserId.ToString();
            opportunity.UpdatedDate = DateTime.Now;
            Update(opportunity);
            Server.Transfer("Detail.aspx?showResult=True&id=" + OpportunityID);
        }
        ClearFiels();
    }
    private void BindFieldsToOpportunity(TBL_OPPORTUNITIES opportunity)
    {
        if (!string.IsNullOrEmpty(CloseDate.Text))
            opportunity.CLOSEDATE = Convert.ToDateTime(CloseDate.Text);
        if (!string.IsNullOrEmpty(txtBxCreationDate.Text))
            opportunity.CreationDate = Convert.ToDateTime(txtBxCreationDate.Text);
        opportunity.COMPANYID = int.Parse(ddlCompany.SelectedValue);
        opportunity.NAME = txtOppName.Text;
        if (ddlProducts.SelectedIndex > 0)
            opportunity.ProductID = int.Parse(ddlProducts.SelectedValue);
        opportunity.SALESREPFIRSTNAME = txtSalesRepFName.Text;
        opportunity.SALESREPLASTNAME = txtSalesRepLName.Text;
        opportunity.SALESREPPHONE = txtSalesRepPhone.Text;
        if (ddlProductStatus.SelectedIndex > 0)
            opportunity.STATUSID = int.Parse(ddlProductStatus.SelectedValue);
        else
            opportunity.STATUSID = null;
        opportunity.VALUE = decimal.Parse(txtOpportunityValue.Text);
        opportunity.WINPROBABILITY = txtWinProbability.Text;
        if(!string.IsNullOrEmpty(opportunity.WINPROBABILITY))
            opportunity.WEIGHTEDVALUE = (opportunity.VALUE * int.Parse(opportunity.WINPROBABILITY)) / 100;
        if (ddlSource.SelectedIndex > 0)
            opportunity.SourceID = int.Parse(ddlSource.SelectedValue);
        else
            opportunity.SourceID = null;
        if (ddlTypes.SelectedIndex > 0)
            opportunity.TypeID = int.Parse(ddlTypes.SelectedValue);
        else
            opportunity.TypeID = null;
        if (ddlWhyLost.SelectedIndex > 0)
            opportunity.WhyLostID = int.Parse(ddlWhyLost.SelectedValue);
        else
            opportunity.WhyLostID = null;
        opportunity.Description = txtDescription.Text;
        opportunity.Notes = txtNotes.Text;
        if (!string.IsNullOrEmpty(txtActualValue.Text))
            opportunity.ActualValue = Convert.ToDecimal(txtActualValue.Text);

        int[] selectedItemIndexes = lstBxContacts.GetSelectedIndices();

        opportunity.CONTACTID = int.Parse(lstBxContacts.Items[selectedItemIndexes[0]].Value);

        if (selectedItemIndexes.Count() > 1)
            opportunity.SeconadryContactId1 = int.Parse(lstBxContacts.Items[selectedItemIndexes[1]].Value);
        if (selectedItemIndexes.Count() > 2)
            opportunity.SeconadryContactId2 = int.Parse(lstBxContacts.Items[selectedItemIndexes[2]].Value);
        opportunity.ProductCost = (string.IsNullOrEmpty(txtProductCost.Text)) ? 0 : Convert.ToDecimal(txtProductCost.Text);
        //Pain related data Feb 10 changes
        opportunity.Pain = txtPain.Text;
        opportunity.LengthOfProblem = txtPainLengthProblem.Text;
        opportunity.Alternatives = txtAlternatives.Text;
        opportunity.CostToFix = txtCostToFix.Text;
        opportunity.IsBudgeIdentified = Convert.ToBoolean(ddlBudgetIdentified.SelectedValue);
        opportunity.IsMoveForward = Convert.ToBoolean(ddlMoveForward.SelectedValue);
    }
 private void BindFieldsToOpportunity(TBL_OPPORTUNITIES opportunity, GridViewRow row)
 {
     opportunity.NAME = (row.FindControl("txtName") as TextBox).Text;
     if (!string.IsNullOrEmpty((row.FindControl("txtValue") as TextBox).Text))
         opportunity.VALUE = decimal.Parse((row.FindControl("txtValue") as TextBox).Text);
     if (!string.IsNullOrEmpty((row.FindControl("txtCloseDt") as TextBox).Text))
         opportunity.CLOSEDATE = Convert.ToDateTime((row.FindControl("txtCloseDt") as TextBox).Text);
     opportunity.SALESREPFIRSTNAME = (row.FindControl("txtSalesFN") as TextBox).Text;
     opportunity.SALESREPLASTNAME = (row.FindControl("txtSalesLN") as TextBox).Text;
     if ((row.FindControl("ddlProductStatus") as DropDownList).SelectedIndex > 0)
         opportunity.STATUSID = int.Parse((row.FindControl("ddlProductStatus") as DropDownList).SelectedValue);
     else
         opportunity.STATUSID = null;
     opportunity.Notes = (row.FindControl("txtNotes") as TextBox).Text;
 }