Пример #1
0
        public IActionResult mito([FromBody] Mito mito)
        {
            if (!HttpContext.Request.Headers.ContainsKey("tokenValue") || !Auth.getAuth().isLogged(HttpContext.Request.Headers["tokenValue"]))
            {
                return(BadRequest());
            }

            if (mito == null)
            {
                return(BadRequest());
            }

            if (mito.AuthorId != Auth.getAuth().getLoggedUser(HttpContext.Request.Headers["tokenValue"]).Id)
            {
                return(BadRequest());
            }

            if (m_context.Users.FirstOrDefault(u => u.Id == mito.AuthorId) == null)
            {
                return(BadRequest());
            }

            m_context.Add(mito);
            m_context.SaveChanges();

            return(CreatedAtRoute("GetMito", new { id = mito.Id }, mito));
        }
Пример #2
0
        public IActionResult register([FromBody] User user)
        {
            if (user == null)
            {
                return(BadRequest());
            }

            if (m_context.Users.FirstOrDefault(u => u.Email == user.Email) != null)
            {
                return(BadRequest());
            }

            m_context.Add(user);
            m_context.SaveChanges();

            return(CreatedAtRoute("GetUser", new { id = user.Id }, user));
        }