コード例 #1
0
        public async Task EditAsync(int id, string name, string description, IEnumerable <string> opportunityMembers)
        {
            var opportunity = await this.db.Opportunities.FirstOrDefaultAsync(o => o.Id == id);

            if (opportunity == null)
            {
                return;
            }

            opportunity.Name        = name;
            opportunity.Description = description;

            //TODO: Fix logic below for updating Opportunity Members
            this.db.UserOpportunities.RemoveRange(this.db.UserOpportunities.Where(uo => uo.OpportunityId == id));
            await this.db.SaveChangesAsync();

            if (opportunityMembers != null)
            {
                foreach (var userId in opportunityMembers)
                {
                    var userInOpportunity = new UserOpportunity
                    {
                        OpportunityId = id,
                        UserId        = userId
                    };

                    this.db.Add(userInOpportunity);
                }

                await this.db.SaveChangesAsync();
            }
        }
コード例 #2
0
        public async Task CreateAsync(string name, string description, int accountId, IEnumerable <string> opportunityMembers)
        {
            var creationDate = DateTime.UtcNow;

            var opportunity = new Opportunity
            {
                Name         = name,
                Description  = description,
                CreationDate = creationDate,
                AccountId    = accountId
            };

            await this.db.AddAsync(opportunity);

            await this.db.SaveChangesAsync();

            if (opportunityMembers != null)
            {
                var opportunityId = opportunity.Id;
                foreach (var userId in opportunityMembers)
                {
                    var userInOpportunity = new UserOpportunity
                    {
                        OpportunityId = opportunityId,
                        UserId        = userId
                    };

                    this.db.Add(userInOpportunity);
                }

                await this.db.SaveChangesAsync();
            }
        }