Example #1
0
        public IHttpActionResult SaveActivity([FromBody] Activity activity)
        {
            if (activity.SuccessManagerId == 0)
            {
                UserInfoModel currentuser = GetUserInfo();
                activity.SuccessManagerId = currentuser.SuccessManagerId;
            }
            //get the list of agents already
            List <DocketAgent> existingVals = _repository.DocketAgents.Where(x => x.SuccessManagerId == activity.SuccessManagerId).ToList();

            try
            {
                DataWriter dw    = new DataWriter();
                int        actID = dw.SaveDocketActivity(activity);
                activity.Id = actID;
                if (actID > 0)
                {
                    return(Ok(activity));
                }
                return(StatusCode(HttpStatusCode.BadRequest));
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    return(InternalServerError(e.InnerException));
                }
                return(InternalServerError(e));
            }
        }
Example #2
0
        public IHttpActionResult GetAgentActivity(int activityId)
        {
            //this is the call that gets the activity so show the agent so they can respond to it
            Activity        activityResult        = _repository.Activities.FirstOrDefault(x => x.Id == activityId);
            AccountActivity accountActivityResult = _repository.AccountActivities.FirstOrDefault(x => x.ActivtityId == activityId);

            return(Ok(new { activity = activityResult, accountActivity = accountActivityResult }));
        }
Example #3
0
        public IHttpActionResult GetActivityAndAgents(int activityId)
        {
            Activity activity = _repository.ActivityAndAgents.FirstOrDefault(x => x.Id == activityId);

            if (activity != null)
            {
                //set agents that are already in the AccountActivity table to selected
                activity.Agents.ForEach(x => x.Selected = true);
                //this activity has selected agents that were published too.
                //for the UI we need to show the entire list of agents for the SM
                List <int>         accountsToExclude = activity.Agents.Select(x => x.AccountId).ToList();
                List <DocketAgent> agents            = _repository.DocketAgents.Where(x => x.SuccessManagerId == activity.SuccessManagerId && !accountsToExclude.Contains(x.AccountId)).ToList();
                activity.Agents.AddRange(agents);
                activity.Agents = activity.Agents.OrderBy(x => x.Lastname).ToList();
                return(Ok(activity));
            }
            return(BadRequest("Activity not found"));
        }
Example #4
0
        public IHttpActionResult PublishActivity([FromBody] Activity activity)
        {
            //List<DocketAgent> existingVals = _repository.DocketAgents.Where(x => x.SuccessManagerId == activity.SuccessManagerId).ToList();
            try
            {
                Activity existingActivity = _repository.ActivityAndAgents.FirstOrDefault(x => x.Id == activity.Id);
                if (existingActivity != null)
                {
                    List <DocketAgent> existingVals = existingActivity.Agents.ToList();

                    DataWriter dw = new DataWriter();
                    foreach (DocketAgent agent in activity.Agents)
                    {
                        if (existingVals.Any(x => x.AccountId == agent.AccountId))
                        {
                            if (agent.Selected == existingVals.First(x => x.AccountId == agent.AccountId).Selected)
                            {
                                continue;
                            }
                        }
                        if (agent.Selected)
                        {
                            dw.AddAccountActivity(agent.AccountId, activity.Id);
                        }
                        else
                        {
                            dw.DeleteAccountActivity(agent.AccountId, activity.Id);
                        }
                    }
                    return(Ok());
                }
                return(StatusCode(HttpStatusCode.BadRequest));
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    return(InternalServerError(e.InnerException));
                }
                return(InternalServerError(e));
            }
        }