Exemplo n.º 1
0
        public IActionResult Index(string email = null, string id = null, string name = null)
        {
            var updatedSettings        = _globalAppSettings;
            SamplesTreeViewModel model = null;

            ViewBag.UserId  = 1;
            ViewBag.DraftId = string.IsNullOrEmpty(id) ? "" : id;
            if (email != null)
            {
                var adminToken  = new DashboardModel().GetToken();
                var userDetails = new UserManagement().IsUserExist(email, adminToken.AccessToken);
                if (userDetails != null)
                {
                    updatedSettings             = _tenantModel.GetUpdateSchema(_globalAppSettings, userDetails.Email);
                    updatedSettings.UserDetails = userDetails;
                    ViewBag.UserDisplayName     = userDetails.DisplayName;
                    ViewBag.UserId         = userDetails.UserId;
                    ViewBag.DatasourceName = email.Split('@')[0];// + "_efilecabinet";
                }
                else
                {
                    return(View("Error"));
                }
            }
            else
            {
                updatedSettings        = _tenantModel.GetUpdateSchema(_globalAppSettings);
                ViewBag.DatasourceName = _globalAppSettings.EmbedDetails.Email.Split('@')[0];
                var        adminToken  = new DashboardModel().GetToken();
                ServerUser userDetails = new UserManagement().IsUserExist(_globalAppSettings.EmbedDetails.Email, adminToken.AccessToken);
                ViewBag.UserId = userDetails.UserId;
            }

            var categories = new DashboardModel().GetCategories(email);

            ViewBag.Category          = categories != null && categories.Count > 0 ? categories.FirstOrDefault() : null;
            ViewBag.GlobalAppSettings = updatedSettings;
            if (id != null && name != null)
            {
                ViewBag.DashboardName = name;
            }
            ViewBag.ParentName = "";
            ViewBag.Name       = "";
            if (model != null)
            {
                return(View(model));
            }

            return(View());
        }
Exemplo n.º 2
0
        public IActionResult Index(string categoryName, string sampleName, int tabid = 0, string email = null, bool edit = false, string id = null)
        {
            var                  noResourceFound = false;
            var                  updatedSettings = _globalAppSettings;
            ServerUser           userDetails     = null;
            SamplesTreeViewModel model           = null;

            ViewBag.UserId = 1;
            if (email != null)
            {
                var adminToken = new DashboardModel().GetToken();
                userDetails = new UserManagement().IsUserExist(email, adminToken.AccessToken);
                if (userDetails != null)
                {
                    updatedSettings             = _tenantModel.GetUpdateSchema(_globalAppSettings, userDetails.Email);
                    updatedSettings.UserDetails = userDetails;
                    ViewBag.UserDisplayName     = userDetails.DisplayName;
                    var encrptedEmail = DoEncryption(email);
                    ViewBag.Token  = encrptedEmail;
                    ViewBag.UserId = userDetails.UserId;
                }
                else
                {
                    return(View("Error"));
                }
            }
            else
            {
                updatedSettings             = _tenantModel.GetUpdateSchema(_globalAppSettings);
                updatedSettings.UserDetails = null;
                var adminToken = new DashboardModel().GetToken();
                userDetails    = new UserManagement().IsUserExist(_globalAppSettings.EmbedDetails.Email, adminToken.AccessToken);
                ViewBag.UserId = userDetails.UserId;
                var categories = new DashboardModel().GetCategories(email);
                ViewBag.Categories = categories;
                //return View("Error");
            }


            if (updatedSettings.SamplesCollection != null && updatedSettings.SamplesCollection.Count > 0)
            {
                if (edit && sampleName != null)
                {
                    var item = updatedSettings.SamplesCollection.FirstOrDefault(i => i.Name.ToLower() == sampleName.ToLower());
                    if (item != null)
                    {
                        item.IsEdit = edit;
                    }
                    if (categoryName != null)
                    {
                        var menuItem = updatedSettings.SamplesSchemaCollection.FirstOrDefault(i => i.Name.ToLower() == categoryName.ToLower());
                        if (menuItem != null && menuItem.Samples != null && menuItem.Samples.Count > 0)
                        {
                            var sample = menuItem.Samples.FirstOrDefault(j => j.Name.ToLower() == sampleName.ToLower());
                            sample.IsEdit = edit;
                        }
                    }
                }
                if (categoryName == null)
                {
                    var _model = updatedSettings.SamplesCollection[0];
                    if (_model.HasChild && !_model.AsTab)
                    {
                        var userID = userDetails == null ? 1 : userDetails.UserId;
                        //model = updatedSettings.SamplesCollection.FirstOrDefault(i => (i.ParentId == _model.Id && i.Id != 101 && i.CreatedById == userID));
                        ViewBag.ParentName = model != null ? model.ParentName : "";
                        ViewBag.Name       = model != null ? model.Name : "";
                        noResourceFound    = model == null;
                    }
                    else
                    {
                        model           = _model;
                        ViewBag.Name    = model.Name;
                        noResourceFound = true;
                    }
                }
                else if (sampleName == null)
                {
                    model = updatedSettings.SamplesCollection.FirstOrDefault(i => i.Name.ToLower() == categoryName.ToLower());
                    if (model != null)
                    {
                        ViewBag.Name    = model.Name;
                        noResourceFound = !model.HasChild;
                    }
                }
                else
                {
                    sampleName = sampleName.Contains("&") ? sampleName.Substring(0, sampleName.IndexOf("&")) : sampleName;
                    model      = updatedSettings.SamplesCollection.FirstOrDefault(i => i.Name.ToLower() == sampleName.ToLower() && i.CategoryName.ToLower() == categoryName.ToLower());
                    if (model != null)
                    {
                        ViewBag.ParentName = model.ParentName;
                        ViewBag.Name       = model.Name;
                    }
                    ViewBag.IsEdit = edit;
                    if (edit)
                    {
                        var categories = new DashboardModel().GetCategories(email);
                        ViewBag.Category = categories.Where(x => x.Name == model.DashboardPath.Split('/')[1]).FirstOrDefault();
                    }
                }
            }
            ViewBag.DraftId = string.IsNullOrEmpty(id) ? "" : id;
            if (categoryName != null && categoryName != "all")
            {
                List <SamplesSchemaViewModel> sampleCollection = new List <SamplesSchemaViewModel>();
                foreach (var sample in _globalAppSettings.SamplesSchemaCollection[0].Samples)
                {
                    if (sample.CategoryName != null && sample.CategoryName.ToLower() == categoryName)
                    {
                        sampleCollection.Add(sample);
                    }
                    else if (categoryName == "All")
                    {
                        sampleCollection.Add(sample);
                    }
                }
                ViewBag.CategoryName = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(categoryName.ToLower());

                updatedSettings.SamplesSchemaCollection[0].Samples = sampleCollection;
            }
            ViewBag.GlobalAppSettings = updatedSettings;
            ViewBag.NoResourceFound   = noResourceFound;
            if (model != null)
            {
                return(View(model));
            }
            return(View());
        }