Example #1
0
        public async Task <IHttpActionResult> GetPetsAlertsById()
        {
            List <TaskAlertViewModel> taskAlerts = new List <TaskAlertViewModel>();

            var userId = User.Identity.GetUserId <int>();

            TaskService taskService = new TaskService(DbContext);

            taskService.ActivitiesA(DateTime.Now, userId);

            var pets = DbContext.Pets.Where(o => o.OwnerId == userId).Select(x => x.Id).ToList();

            var result = DbContext.TaskAlerts
                         .Where(x => x.DateConfirmed == null)
                         .Where(x => pets.Contains(x.PetId))
                         .ToList();

            foreach (TaskAlert item in result)
            {
                var task = new TaskAlertViewModel
                {
                    Id            = item.Id,
                    Title         = PrepareTitle(item),
                    Msg           = PrepareMsg(item),
                    Description   = item.Description,
                    TaskAlertType = item.TaskAlertType,
                    DateCreated   = item.DateCreated,
                    PetId         = item.PetId,
                    Pet           = Mapper.Map <PetViewModel>(item.Pet),
                    DateConfirmed = item.DateConfirmed,
                    DateTo        = item.DateTo,
                    DateFrom      = item.DateFrom
                };

                taskAlerts.Add(task);
            }

            return(Ok(taskAlerts));
        }