예제 #1
0
        /// <summary>
        /// Create an opportunity
        /// </summary>
        /// <param name="ownerPartyId"></param>
        /// <param name="orgExternalRef"></param>
        /// <param name="contactExternalRef"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public long?CreateOpportunity(long?ownerPartyId, long?orgExternalRef, long?contactExternalRef, string name)
        {
            IOpportunityService service = OpportunityService.GetService();
            OpportunityModel    model   = new OpportunityModel();

            model.Name = name;

            if (orgExternalRef != null)
            {
                model.TargetPartyId          = (long)orgExternalRef;
                model.TargetPartyIdSpecified = true;
            }

            model.OwnerResourcePartyId          = (long)ownerPartyId;
            model.OwnerResourcePartyIdSpecified = true;
            model.KeyContactId          = contactExternalRef;
            model.KeyContactIdSpecified = true;

            OpportunityResourceModel resourceModel = new OpportunityResourceModel();

            resourceModel.OwnerFlag           = true;
            resourceModel.OwnerFlagSpecified  = true;
            resourceModel.ResourceId          = (long)ownerPartyId;
            resourceModel.ResourceIdSpecified = true;

            model.OpportunityResourceModel = resourceModel;

            OpportunityModel result = service.CreateOpportunity(model);

            if (result != null && result.OpportunityId != null)
            {
                return(result.OpportunityId);
            }
            return(null);
        }
예제 #2
0
        public ActionResult Create([Bind(Exclude = "Id")] Opportunity opportunity)
        {
            string userName  = this.User.Identity.Name;
            int    accountId = Int32.Parse(Request.Form["Opportunity.AccountId"]);/*we prefix, as the account is inside the Opportunity editor*/

            //we get the user responsible for the opportunity
            User responsibleUser = _userService.GetUser(userName);
            //we get the account from the db
            Account account = _accountService.GetAccount(accountId);

            opportunity.ResponsibleUser = responsibleUser;
            opportunity.Account         = account;

            if (!_opportunityService.CreateOpportunity(opportunity))
            {
                var accounts  = _accountService.ListAccounts();
                var viewModel = new OpportunityViewModel(opportunity)
                {
                    Accounts = new SelectList(accounts, "Id", "Name")
                };

                return(View(viewModel));
            }

            return(RedirectToAction("Index"));
        }