Ejemplo n.º 1
0
        public WidgetConfModel[] GetWidgetConf(uint widgetId, UserPublicModel user, int offset, int limit)
        {
            (offset, limit) = RangeHelper.CheckRange(offset, limit, 20);
            var widget = _widgetRepository.GetWidgetById(widgetId);

            return(widget != null?_widgetConfRepository.GetWidgetConfByWidgetUserId(widgetId, user.Id, offset, limit) : null);
        }
Ejemplo n.º 2
0
        public int DeleteWidgetConf(int id, UserPublicModel currentUser)
        {
            var target = _widgetConfRepository.GetWidgetConfById(id);

            if (target.UserId != currentUser.Id)
            {
                return(0);
            }

            return(_widgetConfRepository.DeleteWidgetConf(target) == 1 ? 1 : 0);
        }
Ejemplo n.º 3
0
        public UserPublicModel GetCurrentUser(ClaimsPrincipal user)
        {
            var currentUser = new UserPublicModel
            {
                Id       = uint.Parse(user.FindFirst(ClaimTypes.Name)?.Value),
                Username = user.FindFirst("Username")?.Value,
                Email    = user.FindFirst(ClaimTypes.Email)?.Value,
                Date     = DateTimeOffset.Parse(user.FindFirst("DateOfJoin")?.Value)
            };


            return(currentUser);
        }
Ejemplo n.º 4
0
        public WidgetConfModel UpdateWidgetConf(int id, UserPublicModel currentUser, WidgetConfUpdateModel updateModel)
        {
            var target  = _widgetConfRepository.GetWidgetConfById(id);
            var toPatch = target;

            if (toPatch == null || toPatch.UserId != currentUser.Id)
            {
                return(null);
            }
            toPatch.Conf      = updateModel.Conf;
            toPatch.UpdatedAt = DateTimeOffset.Now;

            return(_widgetConfRepository.UpdateWidgetConf(target, toPatch) == 1 ? toPatch : null);
        }
Ejemplo n.º 5
0
        public UserPublicModel GetUserById(int id)
        {
            var user       = _repository.GetUserById(id);
            var publicUser = new UserPublicModel();

            if (user == null)
            {
                return(null);
            }
            publicUser.Id       = user.Id;
            publicUser.Username = user.Username;
            publicUser.Email    = user.Email;
            publicUser.Date     = user.Date;
            return(publicUser);
        }
Ejemplo n.º 6
0
        public WidgetConfModel AddWidgetConf(int widgetId, UserPublicModel user, WidgetConfCreationModel newConf)
        {
            var widget = _widgetRepository.GetWidgetById((uint)widgetId);

            if (widget == null)
            {
                return(null);
            }

            var widgetConf = new WidgetConfModel
            {
                Conf     = newConf.Conf,
                WidgetId = (uint)widgetId,
                UserId   = user.Id
            };

            return(_widgetConfRepository.AddNewWidgetConf(widgetConf) == 1
                ? _widgetConfRepository.GetLastWidgetConfByUserId(user.Id)
                : null);
        }
Ejemplo n.º 7
0
        public string GetData(int confId, UserPublicModel currentUser)
        {
            var conf = _widgetConfRepository.GetWidgetConfById(confId);

            if (conf == null || conf.UserId != currentUser.Id)
            {
                return(null);
            }
            var widget = _widgetRepository.GetWidgetById(conf.WidgetId);

            if (widget == null)
            {
                return(null);
            }
            var service = _serviceRepository.GetServiceById(widget.ServiceId);

            if (service == null)
            {
                return(null);
            }
            var provider = _providerRepository.GetProviderById(service.ProvId);

            if (provider == null)
            {
                return(null);
            }
            var(route, method, form, token) = ParsConf(conf.Conf, provider);
            if (route == null || method == null)
            {
                return(null);
            }

            return(method switch
            {
                "get" => _workerRepository.Get(route, token),
                "post" => _workerRepository.Post(route, form, token),
                _ => null
            });