public ActionResult UnzipFile(string fineName)
        {
            PrivateTemplate privateTemplate = new PrivateTemplate();
            string          extractPath     = string.Empty;

            try
            {
                if (!System.IO.Directory.Exists(Server.MapPath("~") + @"\Logs"))
                {
                    Directory.CreateDirectory(Server.MapPath("~") + @"\Logs");
                }
                if (!Directory.Exists(Server.MapPath("~") + @"\PrivateTemplates"))
                {
                    Directory.CreateDirectory(Server.MapPath("~") + @"\PrivateTemplates");
                }
                //Deleting uploaded zip files present from last one hour
                string extractedZipFile = HostingEnvironment.MapPath("~") + @"ExtractedZipFile\";
                if (Directory.Exists(extractedZipFile))
                {
                    string[] subdirs = Directory.GetFiles(extractedZipFile)
                                       .Select(Path.GetFileName)
                                       .ToArray();
                    foreach (string _file in subdirs)
                    {
                        FileInfo d = new FileInfo(extractedZipFile + _file);
                        if (d.CreationTime < DateTime.Now.AddHours(-1))
                        {
                            System.IO.File.Delete(extractedZipFile + _file);
                        }
                    }
                }

                string zipPath = Server.MapPath("~/ExtractedZipFile/" + fineName);
                string folder  = fineName.Replace(".zip", "");
                privateTemplate.privateTemplateName = folder;

                extractPath = Server.MapPath("~/PrivateTemplates/" + folder);
                System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, extractPath);
                System.IO.File.Delete(zipPath);
                privateTemplate.privateTemplatePath = templateService.FindPrivateTemplatePath(extractPath);

                privateTemplate.responseMessage = templateService.checkSelectedTemplateIsPrivate(privateTemplate.privateTemplatePath);

                bool isExtracted = templateService.checkTemplateDirectory(privateTemplate.privateTemplatePath);
                if (!isExtracted)
                {
                    Directory.Delete(extractPath, true);
                }
            }
            catch (Exception ex)
            {
                ProjectService.logger.Info(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n");
                Directory.Delete(extractPath, true);
                return(Json(ex.Message));
            }
            return(Json(privateTemplate, JsonRequestBehavior.AllowGet));
        }
        public JsonResult UploadPrivateTemplateFromURL(string TemplateURL, string token, string userId, string password, string OldPrivateTemplate = "")
        {
            if (Session["visited"] != null)
            {
                if (!string.IsNullOrEmpty(OldPrivateTemplate))
                {
                    templateService.deletePrivateTemplate(OldPrivateTemplate);
                }
                PrivateTemplate privateTemplate = new PrivateTemplate();
                string          templatePath    = string.Empty;
                try
                {
                    string templateName = "";
                    string fileName     = Path.GetFileName(TemplateURL);
                    string extension    = Path.GetExtension(TemplateURL);
                    templateName = fileName.ToLower().Replace(".zip", "").Trim() + "-" + Guid.NewGuid().ToString().Substring(0, 6) + extension.ToLower();
                    privateTemplate.privateTemplateName = templateName.ToLower().Replace(".zip", "").Trim();
                    privateTemplate.privateTemplatePath = templateService.GetTemplateFromPath(TemplateURL, templateName, token, userId, password);

                    if (privateTemplate.privateTemplatePath != "")
                    {
                        privateTemplate.responseMessage = templateService.checkSelectedTemplateIsPrivate(privateTemplate.privateTemplatePath);
                        if (privateTemplate.responseMessage != "SUCCESS")
                        {
                            var templatepath = HostingEnvironment.MapPath("~") + @"\PrivateTemplates\" + templateName.ToLower().Replace(".zip", "").Trim();
                            if (Directory.Exists(templatepath))
                            {
                                Directory.Delete(templatepath, true);
                            }
                        }
                    }
                    else
                    {
                        privateTemplate.responseMessage = "Unable to download file, please check the provided URL";
                    }
                }
                catch (Exception ex)
                {
                    ProjectService.logger.Info(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n");
                    return(Json(new { message = "Error", status = "false" }, JsonRequestBehavior.AllowGet));
                }
                return(Json(privateTemplate, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("Session Expired", JsonRequestBehavior.AllowGet));
            }
        }
        public PrivateTemplate UploadPrivateTempalteFromHome(string TemplateURL)
        {
            PrivateTemplate privateTemplate = new PrivateTemplate();
            string          templatePath    = string.Empty;

            try
            {
                privateTemplate.IsTemplateValid = false;
                string templateName = "";
                string fileName     = Path.GetFileName(TemplateURL);
                string extension    = Path.GetExtension(TemplateURL);
                privateTemplate.privateTemplateOriginalName = fileName.ToLower().Replace(".zip", "").Trim();
                templateName = fileName.ToLower().Replace(".zip", "").Trim() + "-" + Guid.NewGuid().ToString().Substring(0, 6) + extension.ToLower();
                privateTemplate.privateTemplateName = templateName.ToLower().Replace(".zip", "").Trim();
                privateTemplate.privateTemplatePath = templateService.GetTemplateFromPath(TemplateURL, templateName, "", "", "");

                if (privateTemplate.privateTemplatePath != "")
                {
                    privateTemplate.responseMessage = templateService.checkSelectedTemplateIsPrivate(privateTemplate.privateTemplatePath);
                    if (privateTemplate.responseMessage != "SUCCESS")
                    {
                        var templatepath = HostingEnvironment.MapPath("~") + @"\PrivateTemplates\" + templateName.ToLower().Replace(".zip", "").Trim();
                        if (Directory.Exists(templatepath))
                        {
                            Directory.Delete(templatepath, true);
                        }
                    }
                    if (privateTemplate.responseMessage == "SUCCESS")
                    {
                        privateTemplate.IsTemplateValid = true;
                    }
                }
                else
                {
                    privateTemplate.responseMessage = "Unable to download file, please check the provided URL";
                    privateTemplate.IsTemplateValid = false;
                }
            }
            catch (Exception ex)
            {
                ProjectService.logger.Info(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n");
            }
            return(privateTemplate);
        }
        public ActionResult UnzipFile(string fineName)
        {
            PrivateTemplate privateTemplate = new PrivateTemplate();
            string          extractPath     = string.Empty;

            try
            {
                if (!System.IO.Directory.Exists(Server.MapPath("~") + @"\Logs"))
                {
                    Directory.CreateDirectory(Server.MapPath("~") + @"\Logs");
                }
                if (!Directory.Exists(Server.MapPath("~") + @"\PrivateTemplates"))
                {
                    Directory.CreateDirectory(Server.MapPath("~") + @"\PrivateTemplates");
                }

                string zipPath = Server.MapPath("~/ExtractedZipFile/" + fineName);
                string folder  = fineName.Replace(".zip", "");
                privateTemplate.privateTemplateName = folder;

                extractPath = Server.MapPath("~/PrivateTemplates/" + folder);
                System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, extractPath);
                System.IO.File.Delete(zipPath);
                privateTemplate.privateTemplatePath = templateService.FindPrivateTemplatePath(extractPath);

                privateTemplate.responseMessage = templateService.checkSelectedTemplateIsPrivate(privateTemplate.privateTemplatePath);

                bool isExtracted = templateService.checkTemplateDirectory(privateTemplate.privateTemplatePath);
                if (!isExtracted)
                {
                    Directory.Delete(extractPath, true);
                }
            }
            catch (Exception ex)
            {
                ProjectService.logger.Info(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + ex.Message + "\t" + "\n" + ex.StackTrace + "\n");
                Directory.Delete(extractPath, true);
                return(Json(ex.Message));
            }
            return(Json(privateTemplate, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Verify(LoginModel model, string id)
        {
            Session.Clear();
            // check to enable extractor
            if (string.IsNullOrEmpty(model.EnableExtractor) || model.EnableExtractor.ToLower() == "false")
            {
                model.EnableExtractor = System.Configuration.ConfigurationManager.AppSettings["EnableExtractor"];
            }
            if (!string.IsNullOrEmpty(model.EnableExtractor))
            {
                Session["EnableExtractor"] = model.EnableExtractor;
            }

            var browser = Request.Browser.Type;

            if (browser.Contains("InternetExplorer"))
            {
                return(RedirectToAction("Unsupported_browser", "Account"));
            }
            try
            {
                if (!string.IsNullOrEmpty(model.name))
                {
                    if (System.IO.File.Exists(Server.MapPath("~") + @"\Templates\TemplateSetting.json"))
                    {
                        string privateTemplatesJson = System.IO.File.ReadAllText(Server.MapPath("~") + @"\Templates\TemplateSetting.json");
                        templates = Newtonsoft.Json.JsonConvert.DeserializeObject <TemplateSelection.Templates>(privateTemplatesJson);
                        if (templates != null)
                        {
                            bool flag = false;
                            foreach (var grpTemplate in templates.GroupwiseTemplates)
                            {
                                foreach (var template in grpTemplate.Template)
                                {
                                    if (template.ShortName != null && template.ShortName.ToLower() == model.name.ToLower())
                                    {
                                        flag = true;
                                        Session["templateName"] = template.Name;
                                    }
                                }
                            }
                            if (flag == false)
                            {
                                Session["templateName"] = null;
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(model.Event))
                {
                    string eventsTemplate = Server.MapPath("~") + @"\Templates\Events.json";
                    if (System.IO.File.Exists(eventsTemplate))
                    {
                        string eventContent = System.IO.File.ReadAllText(eventsTemplate);
                        var    jItems       = JObject.Parse(eventContent);
                        if (jItems[model.Event] != null)
                        {
                            model.Event = jItems[model.Event].ToString();
                        }
                        else
                        {
                            model.Event = string.Empty;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(model.TemplateURL))
                {
                    if (model.TemplateURL.EndsWith(".zip"))
                    {
                        PrivateTemplate _privateTemplate = UploadPrivateTempalteFromHome(model.TemplateURL);
                        if (_privateTemplate.IsTemplateValid)
                        {
                            Session["PrivateTemplateURL"]          = _privateTemplate.privateTemplatePath;
                            Session["PrivateTemplateName"]         = _privateTemplate.privateTemplateName;
                            Session["PrivateTemplateOriginalName"] = _privateTemplate.privateTemplateOriginalName;
                        }
                        else
                        {
                            ViewBag.resMessage = _privateTemplate.responseMessage;
                            return(View(new LoginModel()));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Debug(JsonConvert.SerializeObject(ex, Formatting.Indented) + Environment.NewLine);
            }
            //return RedirectToAction("../account/verify");
            return(View(model));
        }