public async Task<ActionResult> Configuration(ConfigModel viewmodel, IEnumerable<HttpPostedFileBase> files)
        {
            int userId = 0;
            int clientId = 0;
            AdminUser user = null;
            int typeId = 0;
            int langId = 0;
            try
            {
                var cid = Session["ClientId"];
                clientId = Convert.ToInt32(cid.ToString());
                user = (PortalAPI.Models.AdminUser)Session["AdminUserSession"];
                userId = user.UserId;
                string xml = viewmodel.XmlContent;
                string scriptText = viewmodel.TextContent;
                typeId = viewmodel.ConfigType;
                langId = viewmodel.LangId;

                string CONFIG_PATH = Path.Combine(this.DataConfigPath, clientId + "\\" + viewmodel.PortalId + "\\Configuration");
                string LANG_PATH = Path.Combine(this.DataConfigPath, clientId + "\\" + viewmodel.PortalId + "\\Languages");
                string CSS_PATH = Path.Combine(this.DataConfigPath, clientId + "\\" + viewmodel.PortalId + "\\Styles");
                string JS_PATH = Path.Combine(this.DataConfigPath, clientId + "\\" + viewmodel.PortalId + "\\Scripts");

                string CLIENTPATH = clientId + "/" + viewmodel.PortalId;
                string EDITCONTROL = "Edit/" + CLIENTPATH;
                string[] imgExtn = { "jpg", "png", "gif" };

               switch(typeId)
               {
                   case 1:
                       XmlDocument newXml = new XmlDocument();
                       try { 
                           newXml.LoadXml(string.Format("{0}", xml));
                           var edited = _adminManager.WriteXMLFile(CONFIG_PATH + "\\portal-config.xml", newXml);
                           var config = _adminManager.AddConfigDetailPortal(viewmodel.PortalId, clientId, userId, 1, "portal-config.xml");
                           }
                       catch(Exception ex)
                       {
                           KBCustomException.ProcessException(ex, KBOp.AdminConfig, KBErrorHandler.GetMethodName(), GeneralResources.AdminAddConfigDetailPortal,
                               new KBExceptionData("clientId", clientId), new KBExceptionData("userId", userId), new KBExceptionData("user.UserId", (user != null) ? user.UserId : -1),
                               new KBExceptionData("typeId", typeId), new KBExceptionData("langId", langId));
                           return RedirectToAction(EDITCONTROL + "/1", "Admin", new { Msgtype = "2" });
                       }
                       return RedirectToAction(EDITCONTROL + "/1", "Admin", new {  Msgtype = "1" });
                       

                   case 2: XmlDocument langXml = new XmlDocument();
                        var lang = CreateLangDictionary();
                        var langFile = lang[viewmodel.LangId] + ".xml";
                       try
                       {                          
                           langXml.LoadXml(string.Format("{0}", xml));
                           var edited = _adminManager.WriteXMLFile(LANG_PATH + "\\" + langFile, langXml);
                           var config = _adminManager.AddConfigDetailPortal(viewmodel.PortalId, clientId, userId, 2, langFile);
                       }
                       catch (Exception ex)
                       {
                           KBCustomException.ProcessException(ex, KBOp.AdminConfig, KBErrorHandler.GetMethodName(), GeneralResources.AdminAddConfigDetailPortal,
                               new KBExceptionData("clientId", clientId), new KBExceptionData("userId", userId), new KBExceptionData("user.UserId", (user != null) ? user.UserId : -1),
                               new KBExceptionData("typeId", typeId), new KBExceptionData("langId", langId));
                           return RedirectToAction(EDITCONTROL + "/2", "Admin", new { Msgtype = "2" });
                       }
                       return RedirectToAction(EDITCONTROL + "/2", "Admin", new { lang = langFile, Msgtype = "1" });


                   case 3: var newcss = CreateCSSDictionary();
                       int csId = Convert.ToInt32(HttpUtility.ParseQueryString(Request.UrlReferrer.Query)["cssId"]);
                       
                       var cssFile = newcss[csId];
                       try
                       {
                           var edited = _adminManager.WriteTextFile(CSS_PATH + "\\" + cssFile, Convert.ToString(scriptText));
                           var config = _adminManager.AddConfigDetailPortal(viewmodel.PortalId, clientId, userId, 3, cssFile);
                       }
                       catch (Exception ex)
                       {
                           KBCustomException.ProcessException(ex, KBOp.AdminConfig, KBErrorHandler.GetMethodName(), GeneralResources.AdminAddConfigDetailPortal,
                               new KBExceptionData("clientId", clientId), new KBExceptionData("userId", userId), new KBExceptionData("user.UserId", (user != null) ? user.UserId : -1),
                               new KBExceptionData("typeId", typeId), new KBExceptionData("langId", langId));
                           return RedirectToAction(EDITCONTROL + "/3", "Admin");
                       }
                       return RedirectToAction(EDITCONTROL + "/3", "Admin", new { Msgtype = "1" });

                   case 4:
                       try
                       {
                           var comPath = Path.Combine("knowledgebase\\PortalConfiguration", clientId + "\\" + viewmodel.PortalId + "\\" + "Images");
                           var folder = Path.Combine(_adminManager.DataPath, comPath);
                           if (!Directory.Exists(folder))
                               Directory.CreateDirectory(folder);

                           foreach (var file in files)
                           {
                               if (file.ContentLength > 0)
                               {
                                   var fileName = Path.GetFileName(file.FileName);                                  
                                   var path = Path.Combine(folder, fileName);
                                   var extn = fileName.Substring(fileName.Length - 3).ToLower();
                                   if (imgExtn.Any(s => extn.Contains(s)))
                                   {
                                       file.SaveAs(path);
                                       var confg = _adminManager.AddConfigDetailPortal(viewmodel.PortalId, clientId, userId, 4, fileName);
                                   }
                               }
                           }
                       }
                       catch (Exception ex)
                       {
                           KBCustomException.ProcessException(ex, KBOp.AdminConfig, KBErrorHandler.GetMethodName(), GeneralResources.AdminAddConfigDetailPortal,
                               new KBExceptionData("clientId", clientId), new KBExceptionData("userId", userId), new KBExceptionData("user.UserId", (user != null) ? user.UserId : -1),
                               new KBExceptionData("typeId", typeId), new KBExceptionData("langId", langId));
                           return RedirectToAction(EDITCONTROL + "/4", "Admin");
                       }
                       return RedirectToAction(EDITCONTROL + "/4", "Admin");

                   case 5: 
                       try
                       {
                           var edited = _adminManager.WriteTextFile(JS_PATH + "\\portal.js", Convert.ToString(scriptText));
                           var config = _adminManager.AddConfigDetailPortal(viewmodel.PortalId, clientId, userId, 5, "portal.js");
                       }
                       catch (Exception ex)
                       {
                           KBCustomException.ProcessException(ex, KBOp.AdminConfig, KBErrorHandler.GetMethodName(), GeneralResources.AdminAddConfigDetailPortal,
                               new KBExceptionData("clientId", clientId), new KBExceptionData("userId", userId), new KBExceptionData("user.UserId", (user != null) ? user.UserId : -1),
                               new KBExceptionData("typeId", typeId), new KBExceptionData("langId", langId));
                           return RedirectToAction(EDITCONTROL + "/5", "Admin");
                       }
                       return RedirectToAction(EDITCONTROL + "/5", "Admin", new { Msgtype = "1" });

                   default:break;
                }


               return RedirectToAction(EDITCONTROL, "Admin");
            }
            catch (Exception ex)
            {
                KBCustomException kbCustExp = KBCustomException.ProcessException(ex, KBOp.AdminConfig, KBErrorHandler.GetMethodName(), GeneralResources.AdminAddConfigDetailPortal,
                    new KBExceptionData("clientId", clientId), new KBExceptionData("userId", userId), new KBExceptionData("user.UserId", (user != null) ? user.UserId : -1),
                    new KBExceptionData("typeId", typeId), new KBExceptionData("langId", langId));
                throw kbCustExp;
            }
        }
        public async Task<ActionResult> Edit(ConfigModel viewmodel)
        {
            int clientId = 0;
            try
            {
                var cid = Session["ClientId"];
                clientId = Convert.ToInt32(cid.ToString());         

                return View();
            }
            catch (Exception ex)
            {
                KBCustomException kbCustExp = KBCustomException.ProcessException(ex, KBOp.LoadContent, KBErrorHandler.GetMethodName(), GeneralResources.AdminBreadcrumbEditError,
                    new KBExceptionData("clientId", clientId));
                throw kbCustExp;
            }
        }