Exemplo n.º 1
0
      //  [Authorize(Roles = "Admin,AccountAdmin,AccountUser")]  TO-DO add authorization
        public async Task<HttpResponseMessage> AddOpportunity(AddOpportunityModel model)
        {
            try
            {
                //var userId = HttpContext.Current.User.Identity.GetUserId();  coming soon
                var userId = Guid.NewGuid();

                var result = await this._opportunityMgr.SaveOpportunityAsync(userId, model);

                return Request.CreateResponse(HttpStatusCode.OK, new IdOutputModel(result));
            }
            catch (Exception e)
            {
                logger.Debug(e);
                return Request.CreateResponse(HttpStatusCode.BadRequest, new ErrorResultModel(e.Message));
            }

        }
        public async Task<Guid> SaveOpportunityAsync(Guid userId, AddOpportunityModel model)
        {
            //TO-DO validate the model

            //commented out for now
            //var user = await this._userMgr.GetUserById(userId);

            var now = DateTime.UtcNow;
            var opportunity = new Opportunity();
            opportunity.Id = Guid.NewGuid();
            opportunity.CreatedBy = userId;
            opportunity.CreatedOn = now;
            opportunity.UpdatedBy = userId;
            opportunity.UpdatedOn = now;
            opportunity.StatusId = WinEnums.eOpportunityStatus.Open;
            opportunity.Competitor = model.Competitor;
            opportunity.Industry = model.Industry;
            opportunity.AccountId = Guid.Empty;  // user.AccountId;
            opportunity.Amount = 0;
            opportunity.Buyer = string.Empty;
            opportunity.DealLength = 2;
            opportunity.Headline = "headline";
            opportunity.ManagerId = Guid.Empty;
            opportunity.MonthsUnderContract = 2;
            opportunity.OpportunityCreateDate = now;
            opportunity.RepId = Guid.Empty;
            opportunity.RepNarrative = string.Empty;
            opportunity.Source = string.Empty;


            this._mainContext.Opportunities.Add(opportunity);

            var result = await this._mainContext.SaveChangesAsync();

            return opportunity.Id;
        }