Exemplo n.º 1
0
        public IActionResult ModPw([FromQuery] string oldPw, [FromQuery] string newPw)
        {
            var auth = HttpContext.AuthenticateAsync();
            var id   = Convert.ToInt32(auth.Result.Principal.Claims.First(t => t.Type.Equals(ClaimTypes.NameIdentifier))
                                       ?.Value);

            if (id >= 10000)
            {
                try
                {
                    rd.ReaderPasswordChange(id, newPw, oldPw);
                }
                catch (Exception ex)
                {
                    return(Ok(new { error = ex.Message }));
                }
            }
            else if (id < 10000 && id >= 1)
            {
                try
                {
                    ad.AdminPasswordChange(id, newPw, oldPw);
                }
                catch (Exception ex)
                {
                    return(Ok(new { error = ex.Message }));
                }
            }
            else
            {
                return(Ok(new { error = "Invalid Id" }));
            }

            return(Ok(GlobalFunc.GetBasicInfo(id)));
        }
Exemplo n.º 2
0
        public IActionResult ModInfo(string contact            = null, [FromQuery] string name = null,
                                     [FromQuery] string gender = null)
        {
            name   = GlobalFunc.MyUrlDeCode(name, Encoding.UTF8);
            gender = GlobalFunc.MyUrlDeCode(gender, Encoding.UTF8);
            var auth = HttpContext.AuthenticateAsync();
            var id   = Convert.ToInt32(auth.Result.Principal.Claims.First(t => t.Type.Equals(ClaimTypes.NameIdentifier))
                                       ?.Value);

            if (id >= 10000)
            {
                var newInfo = new ReaderInfoModel
                {
                    ID      = id,
                    Name    = name,
                    Contact = contact,
                    Gender  = gender
                };
                try
                {
                    rd.ReaderModifyInfo(newInfo);
                }
                catch (Exception ex)
                {
                    return(Ok(new { error = ex.Message }));
                }
            }
            else if (id < 10000 && id >= 1)
            {
                var newInfo = new AdminInfoModel
                {
                    ID      = id,
                    Name    = name,
                    Contact = contact,
                    Gender  = gender
                };
                try
                {
                    ad.AdminModifyInfo(newInfo);
                }
                catch (Exception ex)
                {
                    return(Ok(new { error = ex.Message }));
                }
            }
            else
            {
                return(Ok(new { error = "Invalid Id" }));
            }

            return(Ok(GlobalFunc.GetBasicInfo(id)));
        }