Пример #1
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());
        }