Esempio n. 1
0
        public async Task <IActionResult> Save(LoginListModel.ListItem model)
        {
            try
            {
                await _service.Save(model);

                var result = await _service.GetList(model.SiteId);

                result.Status = new StatusMessage
                {
                    Type = StatusMessage.Success,
                    Body = _localizer.Alias["The UserLogin was successfully added to the list"]
                };

                return(Ok(result));
            }
            catch (ValidationException e)
            {
                var result = new LoginListModel();
                result.Status = new StatusMessage
                {
                    Type = StatusMessage.Error,
                    Body = e.Message
                };
                return(BadRequest(result));
            }
        }
Esempio n. 2
0
        public async Task <LoginListModel> GetList(Guid?siteId = null)
        {
            Site site = null;

            // Ensure that we have a site id
            if (!siteId.HasValue)
            {
                site = await _api.Sites.GetDefaultAsync();

                siteId = site.Id;
            }

            if (site == null)
            {
                site = await _api.Sites.GetByIdAsync(siteId.Value);
            }

            var model = new LoginListModel
            {
                SiteId    = siteId.Value,
                SiteTitle = site.Title
            };

            // Get all available sites
            var sites = await _api.Sites.GetAllAsync();

            model.Sites = sites.Select(s => new LoginListModel.SiteItem
            {
                Id    = s.Id,
                Title = s.Title
            }).ToList();

            // Get all available aliases for the current site
            var userlogins = await _api.UserLogins.GetAllAsync(siteId.Value);

            model.Items = userlogins.Select(a => new LoginListModel.ListItem
            {
                Id           = a.Id,
                SiteId       = a.SiteId,
                UserName     = a.UserName == null ? "" : a.UserName,
                UserPassWord = a.UserPassWord == null ? "" : a.UserPassWord,
                UserPhone    = a.UserPhone == null ? "" : a.UserPhone,
                UserMail     = a.UserMail == null ? "" : a.UserMail,
                UserFacebook = a.UserFacebook == null ? "" : a.UserFacebook,
                UserCare     = a.UserCare == null ? "" : a.UserCare,
            }).ToList();

            return(model);
        }