Esempio n. 1
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);
        }
Esempio n. 2
0
        public ActionResult <string> PostWidgetConf(int id, [FromForm] WidgetConfCreationModel newConf)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var currentUser = _userBusiness.GetCurrentUser(User);

            if (currentUser == null)
            {
                return(Unauthorized());
            }

            var addedConf = _widgetBusiness.AddWidgetConf(id, currentUser, newConf);

            if (addedConf != null)
            {
                return(Ok(addedConf));
            }

            return(BadRequest());
        }