Beispiel #1
0
        public ActionResult AddAMDetails(FormCollection _formcollectionobj)
        {
            var         QuaterObj        = _formcollectionobj.AllKeys.Where(i => i.Contains("txt"));
            int         SalesForceCastID = 0;
            Opportunity _Opportunityobj  = new Opportunity();

            _Opportunityobj.DealStageID         = Convert.ToInt32(_formcollectionobj["DealStageId"]);
            _Opportunityobj.Createddate         = System.DateTime.Now;
            _Opportunityobj.acv                 = decimal.Parse(_formcollectionobj["acv"]);
            _Opportunityobj.AMID                = Convert.ToInt16(_formcollectionobj["AMId"]);
            _Opportunityobj.DBBLDUID            = string.IsNullOrEmpty(_formcollectionobj["DBBLDuId"]) == true ? 0 : Convert.ToInt16(_formcollectionobj["DBBLDuId"]);
            _Opportunityobj.BillingStratDate    = Convert.ToDateTime(_formcollectionobj["BillingStratDate"]);
            _Opportunityobj.OpportunityID       = Convert.ToInt16(_formcollectionobj["OpportunityID"]);
            _Opportunityobj.OpportunityName     = _formcollectionobj["OpportunityName"];
            _Opportunityobj.ProductGroupID      = Convert.ToInt16(_formcollectionobj["ProductGroupId"]);
            _Opportunityobj.ProgramName         = _formcollectionobj["ProgramName"];
            _Opportunityobj.CustomerID          = Convert.ToInt16(_formcollectionobj["CustomerId"]);
            _Opportunityobj.ServiceLineID       = Convert.ToInt16(_formcollectionobj["ServiceLineId"]);
            _Opportunityobj.sowvalue            = Convert.ToInt16(_formcollectionobj["SowStatusId"]);
            _Opportunityobj.TCV                 = decimal.Parse(_formcollectionobj["TCV"]);
            _Opportunityobj.Note                = _formcollectionobj["Note_Comment"];
            _Opportunityobj.Createdby           = Session["UserName"].ToString();
            _Opportunityobj.Createddate         = System.DateTime.Now;
            _Opportunityobj.Modifiedby          = Session["UserName"].ToString();
            _Opportunityobj.ModifiedDate        = System.DateTime.Now;
            _Opportunityobj.SowStatusValue      = decimal.Parse(_formcollectionobj["SowStatusValue"]);
            _Opportunityobj.OpportunityCategory = _formcollectionobj["OpportunityCategory"];
            //if (Convert.ToInt16(_formcollectionobj["DealStageId"]) == 4 && !string.IsNullOrEmpty(_formcollectionobj["OpportunityName"])
            //    /*&& Convert.ToInt16(_formcollectionobj["ProjectId"]) != 0*/)
            //{
            _Opportunityobj.IsActive = true;
            // }
            //else
            //{
            //    _Opportunityobj.IsActive = true;
            //}
            //if(Convert.ToInt16(_formcollectionobj["ProjectId"]) != 0)
            //{
            //    _Opportunityobj.IsMapped = true;
            //}
            //else
            //{
            //    _Opportunityobj.IsMapped = false;
            //}
            _Opportunityobj.IsMapped = false;
            _Opportunityobj.DUID     = Convert.ToInt16(_formcollectionobj["DuId"]);
            _Opportunityobj.LobId    = Convert.ToInt16(_formcollectionobj["LobId"]);

            Random rnd       = new Random();
            string rndmvalue = string.Empty;

            for (int x = 0; x <= 15; x++)
            {
                long salesForceCastIDRndm = rnd.Next(1, 999999999);
                var  value = financetoolentities.OpportunityForecastBySales.Where(i => i.SalesForceCastID == salesForceCastIDRndm).ToList();
                rndmvalue = Convert.ToString(salesForceCastIDRndm);
                if (value.Count > 0)
                {
                    continue;
                }
                else
                {
                    break;
                }
            }
            List <Quater> QuaterList = financetoolentities.Quaters.Where(i => i.IsActive == true).ToList();

            foreach (var dbquater in QuaterList)
            {
                foreach (var Quarter in QuaterObj)
                {
                    if (Quarter.Remove(0, 3).ToString() == dbquater.QuaterName + "_FC ($K)")
                    {
                        OpportunityForecastBySale opportunityForecastBySale = new OpportunityForecastBySale();
                        opportunityForecastBySale.QuaterID             = dbquater.QuaterID;
                        opportunityForecastBySale.forecastvaluebysales = string.IsNullOrEmpty(_formcollectionobj[Quarter].ToString()) == true ? 0 : decimal.Parse(_formcollectionobj[Quarter]);
                        opportunityForecastBySale.SalesForceGuid       = long.Parse(rndmvalue);
                        opportunityForecastBySale.Createdby            = Session["UserName"].ToString();
                        opportunityForecastBySale.Createddate          = System.DateTime.Now;
                        opportunityForecastBySale.Modifiedby           = Session["UserName"].ToString();
                        opportunityForecastBySale.ModifiedDate         = System.DateTime.Now;
                        financetoolentities.OpportunityForecastBySales.Add(opportunityForecastBySale);
                        financetoolentities.SaveChanges();
                        SalesForceCastID = opportunityForecastBySale.SalesForceCastID;
                    }
                }
            }
            _Opportunityobj.SalesForceGuid   = long.Parse(rndmvalue);
            _Opportunityobj.SalesForceCastID = Convert.ToInt16(SalesForceCastID);
            financetoolentities.Opportunities.Add(_Opportunityobj);
            financetoolentities.SaveChanges();
            return(View("DisplayAmDetails", Display()));
        }