Ejemplo n.º 1
0
        public async Task <IActionResult> DeleteConnection([FromBody] int connectionId)
        {
            var loginId = ((Login)HttpContext.Items["Login"]).LoginId;

            var entiry = await ctx.ConnectionTables.Where(c => c.ConnectionId == connectionId && c.LoginId == loginId).FirstOrDefaultAsync();

            if (entiry == null)
            {
                return(BadRequest(new
                {
                    error = true,
                    message = "Not authorized to delete this connection or connection does not exist."
                }));
            }
            //fix for fast request, same remove request
            ctx.Remove(entiry);
            await ctx.SaveChangesAsync();

            return(Ok(new
            {
                error = false,
                message = "Connection successfully deleted."
            }));
        }