예제 #1
0
        public async Task <IActionResult> PutAgentAvailability([FromRoute] int id, [FromBody] AgentAvailability agentAvailability)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != agentAvailability.Id)
            {
                return(BadRequest());
            }

            _context.Entry(agentAvailability).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AgentAvailabilityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create(AgentAvailabilityViewModel agentAvailability)
        {
            //Generate number
            Random rd        = new Random();
            Int32  batchCode = rd.Next(9999);

            agentAvailability.BatchNo = "A-" + batchCode.ToString();

            if (ModelState.IsValid)
            {
                AgentAvailability availability = new AgentAvailability();
                {
                    availability.Id        = agentAvailability.Id;
                    availability.AgentId   = agentAvailability.AgentId;
                    availability.BatchNo   = agentAvailability.BatchNo;
                    availability.StartDate = agentAvailability.StartDate;
                    availability.EndDate   = agentAvailability.EndDate;
                    availability.Days      = agentAvailability.Days;
                    availability.Shift1    = agentAvailability.Shift1;
                    availability.Shift2    = agentAvailability.Shift2;
                    availability.Shift3    = agentAvailability.Shift3;
                    availability.Shift4    = agentAvailability.Shift4;
                }
                _context.Add(availability);
                await _context.SaveChangesAsync();

                AgentAvailabilityDetailsViewModel details = new AgentAvailabilityDetailsViewModel();

                int id = availability.Id;

                details.AgentAvailabillityId = availability.Id;


                Util util = new Util();
                foreach (DateTime day in util.EachDay(agentAvailability.StartDate, agentAvailability.EndDate))
                {
                    //(int)day.DayOfWeek
                    var a = (int)day.DayOfWeek;
                    foreach (char d in agentAvailability.Days)
                    {
                        var val = (int)Char.GetNumericValue(d);
                        if (a == val)
                        {
                            details.Date = day;
                            _context.Add(details.GetModel());
                            await _context.SaveChangesAsync();
                        }
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["AgentId"] = new SelectList(_context.Agent, "Id", "Id", agentAvailability.AgentId);
            agentAvailability.loadLists(_context);
            return(View(agentAvailability));
        }
예제 #3
0
 public AgentAvailabilityViewModel(MerkatoDbContext context, AgentAvailability B) : this(context)
 {
     this.Id        = B.Id;
     this.AgentId   = B.AgentId;
     this.BatchNo   = B.BatchNo;
     this.StartDate = B.StartDate;
     this.EndDate   = B.EndDate;
     this.Days      = B.Days;
     this.Shift1    = B.Shift1;
     this.Shift2    = B.Shift2;
     this.Shift3    = B.Shift3;
     this.Shift4    = B.Shift4;
 }
예제 #4
0
        public AgentAvailability GetModel()
        {
            AgentAvailability b = new AgentAvailability();

            b.Id        = this.Id;
            b.AgentId   = this.AgentId;
            b.BatchNo   = this.BatchNo;
            b.StartDate = this.StartDate;
            b.EndDate   = this.EndDate;
            b.Days      = this.Days;
            b.Shift1    = this.Shift1;
            b.Shift2    = this.Shift2;
            b.Shift3    = this.Shift3;
            b.Shift4    = this.Shift4;

            return(b);
        }
 public void Start()
 {
     _logging = Logging.GetInstance();
     _workgroupConfigurations    = new WorkgroupConfigurations();
     _skillConfigurations        = new SkillConfigurations();
     _agentConfigurations        = new AgentConfigurations();
     _agentLicenseConfigurations = new AgentLicenseConfigurations();
     _scheduleConfigurations     = new ScheduleConfigurations();
     _workgroupPeople            = new WorkgroupPeople();
     _workgroupInteractions      = new WorkgroupInteractions();
     _agentAvailability          = new AgentAvailability();
     //use ipaddress.tryparse and use dns lookup if it fails
     _server1         = System.Configuration.ConfigurationManager.AppSettings["PrimaryServer"];
     _server2         = System.Configuration.ConfigurationManager.AppSettings["SecondaryServer"];
     _user            = System.Configuration.ConfigurationManager.AppSettings["CicUser"];
     _password        = System.Configuration.ConfigurationManager.AppSettings["CicPassword"];
     _connectAttempts = 0;
     Connect();
 }
        private async Task <IActionResult> GetAvailabilityAsync(string authorization, IEnumerable <TimeBlock> constrains, string teamAadObjectId)
        {
            string ssoToken = authorization.Substring("Bearer".Length + 1);

            // build graphConstraints based on timeblocks passed in
            IEnumerable <Graph.TimeSlot> graphConstraints = constrains.Select(constraint =>
            {
                return(new Graph.TimeSlot
                {
                    Start = constraint.StartDateTime.UtcDateTime.ToDateTimeTimeZone(TimeZoneInfo.Utc),
                    End = constraint.EndDateTime.UtcDateTime.ToDateTimeTimeZone(TimeZoneInfo.Utc),
                });
            });

            // check if we are getting availability for the current user or within a team
            List <string>     emailAddresses = new List <string>();
            List <Graph.User> teamMembers    = new List <Graph.User>();

            if (!string.IsNullOrEmpty(teamAadObjectId))
            {
                // add all agents in the team
                teamMembers    = (await GraphUtil.GetMembersInTeamsChannelAsync(teamAadObjectId, this.azureADOptions.Value)).Result.ToList();
                emailAddresses = teamMembers.Select(teammember => teammember.Mail).ToList();
            }

            // make graph call to get availability
            AgentAvailability organizer = new AgentAvailability()
            {
                // TODO: move these claim keys to a consts file
                Id           = this.User.Claims.FirstOrDefault(i => i.Type == "http://schemas.microsoft.com/identity/claims/objectidentifier")?.Value,
                DisplayName  = this.User.Claims.FirstOrDefault(i => i.Type == "name")?.Value,
                Emailaddress = this.User.Claims.FirstOrDefault(i => i.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn")?.Value,
                TimeBlocks   = new List <TimeBlock>(),
            };
            var graphTimeSlotsResponse = await GraphUtil.GetAvailableTimeSlotsAsync(ssoToken, graphConstraints, organizer, this.azureADOptions.Value, 30, emailAddresses);

            // process results into a list of AgentAvailability objects
            List <AgentAvailability> availability = new List <AgentAvailability>();

            foreach (var email in graphTimeSlotsResponse.Keys)
            {
                // look up the team member...if null this is the organizer
                var member = teamMembers.FirstOrDefault(i => i.Mail == email);
                if (member == null)
                {
                    organizer.TimeBlocks = graphTimeSlotsResponse[email];
                    availability.Add(organizer);
                }
                else
                {
                    availability.Add(new AgentAvailability()
                    {
                        Id           = member.Id,
                        DisplayName  = member.DisplayName,
                        Emailaddress = email,
                        TimeBlocks   = graphTimeSlotsResponse[email],
                    });
                }
            }

            // if for self and no availability return the organizer
            if (string.IsNullOrEmpty(teamAadObjectId) && availability.Count == 0)
            {
                availability.Add(organizer);
            }

            return(this.Ok(availability));
        }
예제 #7
0
        /// <summary>
        /// Gets the user available times.
        /// </summary>
        /// <param name="ssoToken">The sso access token used to make request against graph apis.</param>
        /// <param name="constraints">The time constraint for finding free times.</param>
        /// <param name="organizer">The organizer the ssoToken belongs to.</param>
        /// <param name="azureADSettings">The Azure AD application settings.</param>
        /// <param name="maxTimeSlots">The maximum number of time slots to return.</param>
        /// <param name="emailAddresses">Emails.</param>
        /// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
        public static async Task<Dictionary<string, List<TimeBlock>>> GetAvailableTimeSlotsAsync(string ssoToken, IEnumerable<TimeSlot> constraints, AgentAvailability organizer, AzureADSettings azureADSettings, int? maxTimeSlots = null, IEnumerable<string> emailAddresses = null)
        {
            // setup graph client
            var authProvider = CreateOnBehalfOfProvider(azureADSettings, new[] { "Calendars.Read" });
            GraphServiceClient graphServiceClient = new GraphServiceClient(authProvider);

            // define the time constraints
            var timeConstaint = new TimeConstraint
            {
                ActivityDomain = ActivityDomain.Work,
                TimeSlots = constraints,
            };

            // add the attendees
            var attendees = new List<AttendeeBase>();
            foreach (var address in emailAddresses)
            {
                var attendee = new AttendeeBase
                {
                    Type = AttendeeType.Required,
                    EmailAddress = new EmailAddress
                    {
                        Address = address,
                    },
                };

                attendees.Add(attendee);
            }

            bool isMe = emailAddresses.Count() == 0;

            try
            {
                // perform the graph call for find meeting times
                var result = await graphServiceClient.Me.FindMeetingTimes(timeConstraint: timeConstaint, maxCandidates: maxTimeSlots, attendees: attendees, isOrganizerOptional: !isMe, minimumAttendeePercentage: 10)
                    .Request()
                    .WithUserAssertion(new UserAssertion(ssoToken))
                    .PostAsync();

                // return an empty collection if EmptySuggestionsReason returned
                if (!result.EmptySuggestionsReason.Equals(string.Empty))
                {
                    return new Dictionary<string, List<TimeBlock>>();
                }

                // pivot the results from timeblock centric to user centric
                Dictionary<string, List<TimeBlock>> dictionary = new Dictionary<string, List<TimeBlock>>();
                foreach (var timeslot in result.MeetingTimeSuggestions.ToList())
                {
                    if (isMe)
                    {
                        if (timeslot.OrganizerAvailability != FreeBusyStatus.Free)
                        {
                            continue;
                        }

                        if (!dictionary.ContainsKey(organizer.Emailaddress))
                        {
                            dictionary.Add(organizer.Emailaddress, new List<TimeBlock>());
                        }

                        dictionary[organizer.Emailaddress].Add(new TimeBlock()
                        {
                            StartDateTime = timeslot.MeetingTimeSlot.Start.ToDateTimeOffset().ToUniversalTime(),
                            EndDateTime = timeslot.MeetingTimeSlot.End.ToDateTimeOffset().ToUniversalTime(),
                        });
                    }
                    else
                    {
                        foreach (var agent in timeslot.AttendeeAvailability)
                        {
                            if (agent.Availability.GetValueOrDefault(FreeBusyStatus.Unknown) != FreeBusyStatus.Free)
                            {
                                continue;
                            }

                            if (!dictionary.ContainsKey(agent.Attendee.EmailAddress.Address))
                            {
                                dictionary.Add(agent.Attendee.EmailAddress.Address, new List<TimeBlock>());
                            }

                            dictionary[agent.Attendee.EmailAddress.Address].Add(new TimeBlock()
                            {
                                StartDateTime = timeslot.MeetingTimeSlot.Start.ToDateTimeOffset().ToUniversalTime(),
                                EndDateTime = timeslot.MeetingTimeSlot.End.ToDateTimeOffset().ToUniversalTime(),
                            });
                        }
                    }
                }

                return dictionary;
            }
            catch (Exception)
            {
                return new Dictionary<string, List<TimeBlock>>();
            }
        }
예제 #8
0
        public async Task <ApiResult <AgentAvailabilityViewModel> > PostAgentAvailability([FromBody] AgentAvailabilityViewModel agentAvailability)
        {
            ApiResult <AgentAvailabilityViewModel> result = new ApiResult <AgentAvailabilityViewModel>();

            //Generate number
            Random rd        = new Random();
            Int32  batchCode = rd.Next(9999);

            agentAvailability.BatchNo = "A-" + batchCode.ToString();

            if (ModelState.IsValid)
            {
                result.Successfull = 0;

                try
                {
                    AgentAvailability availability = new AgentAvailability();
                    {
                        availability.Id        = agentAvailability.Id;
                        availability.AgentId   = agentAvailability.AgentId;
                        availability.BatchNo   = agentAvailability.BatchNo;
                        availability.StartDate = agentAvailability.StartDate;
                        availability.EndDate   = agentAvailability.EndDate;
                        availability.Days      = agentAvailability.Days;
                        availability.Shift1    = agentAvailability.Shift1;
                        availability.Shift2    = agentAvailability.Shift2;
                        availability.Shift3    = agentAvailability.Shift3;
                        availability.Shift4    = agentAvailability.Shift4;
                    }
                    _context.Add(availability);
                    await _context.SaveChangesAsync();

                    AgentAvailabilityDetailsViewModel details = new AgentAvailabilityDetailsViewModel();

                    int id = availability.Id;

                    details.AgentAvailabillityId = availability.Id;


                    Util util = new Util();
                    foreach (DateTime day in util.EachDay(agentAvailability.StartDate, agentAvailability.EndDate))
                    {
                        //(int)day.DayOfWeek
                        var a = (int)day.DayOfWeek;
                        foreach (char d in agentAvailability.Days)
                        {
                            var val = (int)Char.GetNumericValue(d);
                            if (a == val)
                            {
                                details.Date = day;
                                _context.Add(details.GetModel());
                                await _context.SaveChangesAsync();
                            }
                        }
                    }
                    result.Successfull = 1;
                    result.Model       = agentAvailability;
                }
                catch (Exception ex)
                {
                    result.Error         = "Failed to  Create Availability";
                    result.InternalError = ex.Message;
                    result.Successfull   = 0;
                }
            }

            //return CreatedAtAction("GetAgentAvailability", new { id = agentAvailability.Id }, agentAvailability);
            return(result);
        }
예제 #9
0
 public int AgentsAvailable(int profileId)
 {
     return(AgentAvailability.GetAgentAvailabilityByProfile(profileId));
 }