コード例 #1
0
        public IEnumerable <Users> GetAll()
        {
            var          context = new HarmonyContext();
            List <Users> users   = context.users.ToList <Users>();

            return(users);
        }
コード例 #2
0
        public IActionResult CreateToken(IFormCollection user)
        {
            IActionResult response = Unauthorized();
            var           context  = new HarmonyContext();

            bool isAuthorized = context.users.Any(u => user["email"] == u.Name && user["pass"] == u.Password);

            if (isAuthorized)
            {
                var tokenString = JWT.BuildToken(_config);
                response = Ok(new { token = tokenString });
            }

            return(response);
        }
コード例 #3
0
        public async Task <IActionResult> PostParters(IFormFile file, IFormCollection param)
        {
            //  Getting Employees Attribute
            var filePath = $"{_env.WebRootPath}/images/partners/{file.FileName}";
            var partName = param.ContainsKey("partName") ? param["partName"].ToString() : "No Name Specified";

            try
            {
                //  Copying Image to Server Root Directory
                if (file.Length > 0)
                {
                    using (var stream = new FileStream(filePath, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }
                }

                //Adding Records to Database
                using (var context = new HarmonyContext())
                {
                    var employee = new Employees()
                    {
                        Name      = partName,
                        ImagePath = filePath
                    };

                    context.employees.Add(employee);
                    context.SaveChanges();
                }
            }
            catch (Exception)
            {
                return(BadRequest("Upload Image Failed"));
            }

            return(Ok(filePath));
        }