Exemplo n.º 1
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));
            }
        }