示例#1
0
        public async Task <IEnumerable <WidgetDTO> > GetAllWidgetsForUser(string email)
        {
            try
            {
                AuthController.ValidateAndGetCurrentUserName(this.HttpContext.Request);

                email = email.Replace("'", "");

                List <Widget> widgetList = new List <Widget>();
                widgetList = await context.Widgets.Include(widget => widget.User)
                             .Where(widget => widget.UserID == email)
                             .OrderBy(widget => widget.CreationDateTime)
                             .ToListAsync();

                List <WidgetDTO> widgetDTOList = new List <WidgetDTO>();
                foreach (Widget widget in widgetList)
                {
                    WidgetDTO wgtDTO = new WidgetDTO(widget);

                    if (CallmeController.IsWidgetOutofSubscription(widget, context))
                    {
                        wgtDTO.Status = "Out of Subscription";
                    }
                    else if (await CallmeController.IsWidgetOutofCallAsync(widget, context))
                    {
                        wgtDTO.Status = "Out of Call";
                    }

                    widgetDTOList.Add(wgtDTO);
                }

                return(widgetDTOList);
            }catch (Exception ex)
            {
                throw ex;
            }
        }