public IActionResult Create([FromForm] AppSetting model, IFormFile logo, string logo11, IFormFile loginPageBackground, string loginPageBackground12)
        {
            AlertBack alert = new AlertBack();

            try
            {
                if (ModelState.IsValid)
                {
                    if (logo != null)
                    {
                        ModelState.Clear();
                        model.Logo = Env.GetUploadedFilePath(logo).Result;
                    }
                    else
                    {
                        model.Logo = logo11;
                    }
                    if (loginPageBackground != null)
                    {
                        ModelState.Clear();
                        model.LoginPageBackground = Env.GetUploadedFilePath(loginPageBackground).Result;
                    }
                    else
                    {
                        model.LoginPageBackground = loginPageBackground12;
                    }

                    _appSettingService.Insert(model);
                    alert.Status  = "success";
                    alert.Message = "Register Successfully";
                }
                else
                {
                    alert.Status = "warning";
                    foreach (var key in this.ViewData.ModelState.Keys)
                    {
                        foreach (var err in this.ViewData.ModelState[key].Errors)
                        {
                            alert.Message += err.ErrorMessage + "<br/>";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                alert.Status  = "error";
                alert.Message = ex.Message;
            }

            return(Json(alert));
        }
        public AlertBack PostAppSetting([FromForm] AppSetting model, IFormFile logo, string logo11)
        {
            AlertBack alert = new AlertBack();

            if (ModelState.IsValid)
            {
                if (logo != null)
                {
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/uploads", logo.FileName);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        logo.CopyTo(stream);
                    }
                    ModelState.Clear();
                    model.Logo = logo.FileName;
                }
                else
                {
                    model.Logo = logo11;
                }

                appSettingService.Insert(model);
                alert.status  = "success";
                alert.message = "Register Successfully";
                return(alert);
            }
            else
            {
                alert.status = "warning";
                foreach (var key in this.ModelState.Keys)
                {
                    foreach (var err in this.ModelState[key].Errors)
                    {
                        alert.message += err.ErrorMessage + "<br/>";
                    }
                }
                return(alert);
            }
        }
예제 #3
0
        public ActionResult Index()
        {
            var folderPath  = "~/UserRecords";
            var appSettings = _appSettingService.Queryable().ToList();

            if (!appSettings.Any())
            {
                var settingsPath = Server.MapPath(folderPath);
                var newAppSeting = new AppSetting {
                    Id = EntityIdGenerator.GenerateEntityId(), BiometricTemplatePath = folderPath
                };
                if (!Directory.Exists(settingsPath))
                {
                    Directory.CreateDirectory(settingsPath);
                    var dInfo     = new DirectoryInfo(settingsPath);
                    var dSecurity = dInfo.GetAccessControl();
                    dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
                    dInfo.SetAccessControl(dSecurity);
                }

                _appSettingService.Insert(newAppSeting);
                _unitOfWork.SaveChanges();
            }

            var projects = _projectService.Queryable().ToList();

            if (!projects.Any())
            {
                return(RedirectToAction("SiteActivation", "SiteActivator"));
            }

            var sessionProject = GetProjectInSession();

            if (sessionProject == null)
            {
                return(RedirectToAction("ProjectOptions", "Home"));
            }

            if (string.IsNullOrEmpty(sessionProject.ProjectCode))
            {
                return(RedirectToAction("ProjectOptions", "Home"));
            }
            var project = projects.Where(p => p.ProjectCode == sessionProject.ProjectCode).ToList()[0];

            if (string.IsNullOrEmpty(project?.ProjectCode))
            {
                return(RedirectToAction("ProjectOptions", "Home"));
            }

            if (project.LicenseExpiryDate < DateTime.Today)
            {
                Session["siteStatus"] = "expired";
                return(RedirectToAction("SiteActivation", "SiteActivator", new RouteValueDictionary(new KeyValuePair <string, string>("ProjectExpired", "true"))));
            }

            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            return(View());
        }